Function deleteFileZ [src]
Prototype
pub fn deleteFileZ(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void
Parameters
self: Dir
sub_path_c: [*:0]const u8
Possible Errors
In WASI, this error may occur when the file descriptor does not hold the required rights to unlink a resource by path relative to it.
On Windows, file paths cannot contain these characters: '/', '*', '?', '"', '<', '>', '|'
WASI-only; file paths must be valid UTF-8.
Windows-only; file paths provided by the user must be valid WTF-8. https://simonsapin.github.io/wtf-8/
On Windows, \\server
or \\server\share
was not found.
The Operating System returned an undocumented error code.
This error is in theory not possible, but it would be better to handle this error than to invoke undefined behavior.
When this error code is observed, it usually means the Zig Standard Library needs a small patch to add the error code to the error set for the respective function.
Source
pub fn deleteFileZ(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void {
posix.unlinkatZ(self.fd, sub_path_c, 0) catch |err| switch (err) {
error.DirNotEmpty => unreachable, // not passing AT.REMOVEDIR
error.AccessDenied, error.PermissionDenied => |e| switch (native_os) {
// non-Linux POSIX systems return permission errors when trying to delete a
// directory, so we need to handle that case specifically and translate the error
.macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .solaris, .illumos => {
// Don't follow symlinks to match unlinkat (which acts on symlinks rather than follows them)
const fstat = posix.fstatatZ(self.fd, sub_path_c, posix.AT.SYMLINK_NOFOLLOW) catch return e;
const is_dir = fstat.mode & posix.S.IFMT == posix.S.IFDIR;
return if (is_dir) error.IsDir else e;
},
else => return e,
},
else => |e| return e,
};
}