aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/link.zig41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/link.zig b/src/link.zig
index 7c135a7405..139b12af99 100644
--- a/src/link.zig
+++ b/src/link.zig
@@ -717,19 +717,38 @@ pub const File = struct {
// directly, and remove this function from link.zig.
_ = base;
while (true) {
- std.fs.rename(
- cache_directory.handle,
- tmp_dir_sub_path,
- cache_directory.handle,
- o_sub_path,
- ) catch |err| switch (err) {
- error.PathAlreadyExists => {
+ if (builtin.os.tag == .windows) {
+ // workaround windows `renameW` can't fail with `PathAlreadyExists`
+ // See https://github.com/ziglang/zig/issues/8362
+ if (cache_directory.handle.access(o_sub_path, .{})) |_| {
try cache_directory.handle.deleteTree(o_sub_path);
continue;
- },
- else => |e| return e,
- };
- break;
+ } else |err| switch (err) {
+ error.FileNotFound => {},
+ else => |e| return e,
+ }
+ try std.fs.rename(
+ cache_directory.handle,
+ tmp_dir_sub_path,
+ cache_directory.handle,
+ o_sub_path,
+ );
+ break;
+ } else {
+ std.fs.rename(
+ cache_directory.handle,
+ tmp_dir_sub_path,
+ cache_directory.handle,
+ o_sub_path,
+ ) catch |err| switch (err) {
+ error.PathAlreadyExists => {
+ try cache_directory.handle.deleteTree(o_sub_path);
+ continue;
+ },
+ else => |e| return e,
+ };
+ break;
+ }
}
}