| ... | @@ -1112,6 +1112,16 @@ pub const Dir = struct { | ... | @@ -1112,6 +1112,16 @@ pub const Dir = struct { |
| 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 | os.unlinkat(self.fd, sub_path, 0) catch |err| switch (err) { |
| 1114 | error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR | 1114 | error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR |
| | 1115 | error.AccessDenied => |e| switch (builtin.os.tag) { |
| | 1116 | // non-Linux POSIX systems return EPERM when trying to delete a directory, so |
| | 1117 | // we need to handle that case specifically and translate the error |
| | 1118 | .macosx, .ios, .freebsd, .netbsd, .dragonfly => { |
| | 1119 | const fstat = os.fstatat(self.fd, sub_path, 0) catch return e; |
| | 1120 | const is_dir = fstat.mode & os.S_IFMT == os.S_IFDIR; |
| | 1121 | return if (is_dir) error.IsDir else e; |
| | 1122 | }, |
| | 1123 | else => return e, |
| | 1124 | }, |
| 1115 | else => |e| return e, | 1125 | else => |e| return e, |
| 1116 | }; | 1126 | }; |
| 1117 | } | 1127 | } |
| ... | @@ -1122,6 +1132,16 @@ pub const Dir = struct { | ... | @@ -1122,6 +1132,16 @@ pub const Dir = struct { |
| 1122 | pub fn deleteFileZ(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void { | 1132 | pub fn deleteFileZ(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void { |
| 1123 | os.unlinkatZ(self.fd, sub_path_c, 0) catch |err| switch (err) { | 1133 | os.unlinkatZ(self.fd, sub_path_c, 0) catch |err| switch (err) { |
| 1124 | error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR | 1134 | error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR |
| | 1135 | error.AccessDenied => |e| switch (builtin.os.tag) { |
| | 1136 | // non-Linux POSIX systems return EPERM when trying to delete a directory, so |
| | 1137 | // we need to handle that case specifically and translate the error |
| | 1138 | .macosx, .ios, .freebsd, .netbsd, .dragonfly => { |
| | 1139 | const fstat = os.fstatatZ(self.fd, sub_path_c, 0) catch return e; |
| | 1140 | const is_dir = fstat.mode & os.S_IFMT == os.S_IFDIR; |
| | 1141 | return if (is_dir) error.IsDir else e; |
| | 1142 | }, |
| | 1143 | else => return e, |
| | 1144 | }, |
| 1125 | else => |e| return e, | 1145 | else => |e| return e, |
| 1126 | }; | 1146 | }; |
| 1127 | } | 1147 | } |