Skip to content

Commit 1cdc51e

Browse files
leecannonandrewrk
authored andcommitted
handle error.PathAlreadyExists in renameTmpIntoCache
1 parent dd076d8 commit 1cdc51e

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/link.zig

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -672,12 +672,21 @@ pub const File = struct {
672672
// is not needed we can refactor this into having the frontend do the rename
673673
// directly, and remove this function from link.zig.
674674
_ = base;
675-
try std.fs.rename(
676-
cache_directory.handle,
677-
tmp_dir_sub_path,
678-
cache_directory.handle,
679-
o_sub_path,
680-
);
675+
while (true) {
676+
std.fs.rename(
677+
cache_directory.handle,
678+
tmp_dir_sub_path,
679+
cache_directory.handle,
680+
o_sub_path,
681+
) catch |err| switch (err) {
682+
error.PathAlreadyExists => {
683+
try cache_directory.handle.deleteTree(o_sub_path);
684+
continue;
685+
},
686+
else => |e| return e,
687+
};
688+
break;
689+
}
681690
}
682691

683692
pub fn linkAsArchive(base: *File, comp: *Compilation) !void {

0 commit comments

Comments
 (0)