zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 12aca758c6ee923065d1d64a62e44c8a8fd6cd99 (tree)
parent 505bc9817a2b78c97819f481b3cd98102c7ff964
Author: Ryan Liptak <squeek502@hotmail.com>
Date:   Fri, 26 Jun 2020 17:12:02 -0700

Dir.deleteFile: Fix symlink behavior when translating EPERM to EISDIR

Diffstat:
Mlib/std/fs.zig | 3++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/std/fs.zig b/lib/std/fs.zig @@ -1134,7 +1134,8 @@ pub const Dir = struct { // non-Linux POSIX systems return EPERM when trying to delete a directory, so // we need to handle that case specifically and translate the error .macosx, .ios, .freebsd, .netbsd, .dragonfly => { - const fstat = os.fstatatZ(self.fd, sub_path_c, 0) catch return e; + // Don't follow symlinks to match unlinkat (which acts on symlinks rather than follows them) + const fstat = os.fstatatZ(self.fd, sub_path_c, os.AT_SYMLINK_NOFOLLOW) catch return e; const is_dir = fstat.mode & os.S_IFMT == os.S_IFDIR; return if (is_dir) error.IsDir else e; },