authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-11 17:54:34-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-11 17:54:34-08:00
logf4d6b37068db7ef3b5828dbe2403e65bf64a0f2c
tree0411c9a85e48d316ccfae9daa4e9c8bf2a3e5fa4
parent2de08633800cd458fa657afed25a821236520cd8

Package: handle Windows PathAlreadyExists error code

Unfortunately, error.AccessDenied is ambiguous on Windows when it is returned from fs.rename.

2 files changed, 4 insertions(+), 1 deletions(-)

lib/std/os.zig+3
...@@ -2414,6 +2414,9 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: []const u16, flags: u32) UnlinkatError...@@ -2414,6 +2414,9 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: []const u16, flags: u32) UnlinkatError
2414pub const RenameError = error{2414pub const RenameError = error{
2415 /// In WASI, this error may occur when the file descriptor does2415 /// In WASI, this error may occur when the file descriptor does
2416 /// not hold the required rights to rename a resource by path relative to it.2416 /// not hold the required rights to rename a resource by path relative to it.
2417 ///
2418 /// On Windows, this error may be returned instead of PathAlreadyExists when
2419 /// renaming a directory over an existing directory.
2417 AccessDenied,2420 AccessDenied,
2418 FileBusy,2421 FileBusy,
2419 DiskQuota,2422 DiskQuota,
src/Package.zig+1-1
...@@ -570,7 +570,7 @@ fn renameTmpIntoCache(...@@ -570,7 +570,7 @@ fn renameTmpIntoCache(
570 };570 };
571 continue;571 continue;
572 },572 },
573 error.PathAlreadyExists => {573 error.PathAlreadyExists, error.AccessDenied => {
574 // Package has been already downloaded and may already be in use on the system.574 // Package has been already downloaded and may already be in use on the system.
575 cache_dir.deleteTree(tmp_dir_sub_path) catch |del_err| {575 cache_dir.deleteTree(tmp_dir_sub_path) catch |del_err| {
576 std.log.warn("unable to delete temp directory: {s}", .{@errorName(del_err)});576 std.log.warn("unable to delete temp directory: {s}", .{@errorName(del_err)});