| ... | @@ -1110,20 +1110,18 @@ pub const Dir = struct { | ... | @@ -1110,20 +1110,18 @@ pub const Dir = struct { |
| 1110 | /// Delete a file name and possibly the file it refers to, based on an open directory handle. | 1110 | /// Delete a file name and possibly the file it refers to, based on an open directory handle. |
| 1111 | /// Asserts that the path parameter has no null bytes. | 1111 | /// Asserts that the path parameter has no null bytes. |
| 1112 | pub fn deleteFile(self: Dir, sub_path: []const u8) DeleteFileError!void { | 1112 | pub fn deleteFile(self: Dir, sub_path: []const u8) DeleteFileError!void { |
| 1113 | os.unlinkat(self.fd, sub_path, 0) catch |err| switch (err) { | 1113 | if (builtin.os.tag == .windows) { |
| 1114 | error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR | 1114 | const sub_path_w = try os.windows.sliceToPrefixedFileW(sub_path); |
| 1115 | error.AccessDenied => |e| switch (builtin.os.tag) { | 1115 | return self.deleteFileW(sub_path_w.span().ptr); |
| 1116 | // non-Linux POSIX systems return EPERM when trying to delete a directory, so | 1116 | } else if (builtin.os.tag == .wasi) { |
| 1117 | // we need to handle that case specifically and translate the error | 1117 | os.unlinkatWasi(self.fd, sub_path, 0) catch |err| switch (err) { |
| 1118 | .macosx, .ios, .freebsd, .netbsd, .dragonfly => { | 1118 | error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR |
| 1119 | const fstat = os.fstatat(self.fd, sub_path, 0) catch return e; | 1119 | else => |e| return e, |
| 1120 | const is_dir = fstat.mode & os.S_IFMT == os.S_IFDIR; | 1120 | }; |
| 1121 | return if (is_dir) error.IsDir else e; | 1121 | } else { |
| 1122 | }, | 1122 | const sub_path_c = try os.toPosixPath(sub_path); |
| 1123 | else => return e, | 1123 | return self.deleteFileZ(&sub_path_c); |
| 1124 | }, | 1124 | } |
| 1125 | else => |e| return e, | | |
| 1126 | }; | | |
| 1127 | } | 1125 | } |
| 1128 | | 1126 | |
| 1129 | pub const deleteFileC = @compileError("deprecated: renamed to deleteFileZ"); | 1127 | pub const deleteFileC = @compileError("deprecated: renamed to deleteFileZ"); |