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 {...@@ -4914,6 +4914,7 @@ pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
4914 switch (errno(system.access(path, mode))) {4914 switch (errno(system.access(path, mode))) {
4915 .SUCCESS => return,4915 .SUCCESS => return,
4916 .ACCES => return error.PermissionDenied,4916 .ACCES => return error.PermissionDenied,
4917 .PERM => return error.PermissionDenied,
4917 .ROFS => return error.ReadOnlyFileSystem,4918 .ROFS => return error.ReadOnlyFileSystem,
4918 .LOOP => return error.SymLinkLoop,4919 .LOOP => return error.SymLinkLoop,
4919 .TXTBSY => return error.FileBusy,4920 .TXTBSY => return error.FileBusy,
...@@ -4999,6 +5000,7 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces...@@ -4999,6 +5000,7 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces
4999 switch (errno(system.faccessat(dirfd, path, mode, flags))) {5000 switch (errno(system.faccessat(dirfd, path, mode, flags))) {
5000 .SUCCESS => return,5001 .SUCCESS => return,
5001 .ACCES => return error.PermissionDenied,5002 .ACCES => return error.PermissionDenied,
5003 .PERM => return error.PermissionDenied,
5002 .ROFS => return error.ReadOnlyFileSystem,5004 .ROFS => return error.ReadOnlyFileSystem,
5003 .LOOP => return error.SymLinkLoop,5005 .LOOP => return error.SymLinkLoop,
5004 .TXTBSY => return error.FileBusy,5006 .TXTBSY => return error.FileBusy,