Skip to content

Commit

Permalink
posix: access/accessZ/faccessat/faccessatZ can return AccessDenied or…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
rootbeer authored and alexrp committed Feb 21, 2025
1 parent a8d3760 commit 8d9bb97
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/std/posix.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4914,6 +4914,7 @@ pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
switch (errno(system.access(path, mode))) {
.SUCCESS => return,
.ACCES => return error.PermissionDenied,
.PERM => return error.PermissionDenied,
.ROFS => return error.ReadOnlyFileSystem,
.LOOP => return error.SymLinkLoop,
.TXTBSY => return error.FileBusy,
Expand Down Expand Up @@ -4999,6 +5000,7 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces
switch (errno(system.faccessat(dirfd, path, mode, flags))) {
.SUCCESS => return,
.ACCES => return error.PermissionDenied,
.PERM => return error.PermissionDenied,
.ROFS => return error.ReadOnlyFileSystem,
.LOOP => return error.SymLinkLoop,
.TXTBSY => return error.FileBusy,
Expand Down

0 comments on commit 8d9bb97

Please sign in to comment.