authorgravatar for pat.github@tullmann.orgPat Tullmann <pat.github@tullmann.org> 2025-02-18 17:04:19-08:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-02-21 07:29:15+01:00
log8d9bb9746165abf067851f490cfea8c49fbd59ea
tree44fb283773dcc88f532ead40be9ac20cf9c242d5
parenta8d3760c5bc31ed114516c89f31d9107b803a6b7

posix: access/accessZ/faccessat/faccessatZ can return AccessDenied or PermissionDenied

`EACCES` is returned if the file mode bit (i.e., user/group/other rwx bits) disallow access. `EPERM` is returned if something else denies access (immutable bit, SELinux, capabilities, etc). This somewhat subtle no-access distinction is part of POSIX. For now map both to `error.PermissionDenied` to keep the error signature unchanged. See duopoly. This PR is effecitvely an update/simplification of PR #19193. Tested locally with an immutable file. Fixes #22733 and #19162.

1 files changed, 2 insertions(+), 0 deletions(-)

lib/std/posix.zig+2
......@@ -4914,6 +4914,7 @@ pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
49144914 switch (errno(system.access(path, mode))) {
49154915 .SUCCESS => return,
49164916 .ACCES => return error.PermissionDenied,
4917 .PERM => return error.PermissionDenied,
49174918 .ROFS => return error.ReadOnlyFileSystem,
49184919 .LOOP => return error.SymLinkLoop,
49194920 .TXTBSY => return error.FileBusy,
......@@ -4999,6 +5000,7 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces
49995000 switch (errno(system.faccessat(dirfd, path, mode, flags))) {
50005001 .SUCCESS => return,
50015002 .ACCES => return error.PermissionDenied,
5003 .PERM => return error.PermissionDenied,
50025004 .ROFS => return error.ReadOnlyFileSystem,
50035005 .LOOP => return error.SymLinkLoop,
50045006 .TXTBSY => return error.FileBusy,