| ... | ... | @@ -717,19 +717,38 @@ pub const File = struct { |
| 717 | 717 | // directly, and remove this function from link.zig. |
| 718 | 718 | _ = base; |
| 719 | 719 | while (true) { |
| 720 | | std.fs.rename( |
| 721 | | cache_directory.handle, |
| 722 | | tmp_dir_sub_path, |
| 723 | | cache_directory.handle, |
| 724 | | o_sub_path, |
| 725 | | ) catch |err| switch (err) { |
| 726 | | error.PathAlreadyExists => { |
| 720 | if (builtin.os.tag == .windows) { |
| 721 | // workaround windows `renameW` can't fail with `PathAlreadyExists` |
| 722 | // See https://github.com/ziglang/zig/issues/8362 |
| 723 | if (cache_directory.handle.access(o_sub_path, .{})) |_| { |
| 727 | 724 | try cache_directory.handle.deleteTree(o_sub_path); |
| 728 | 725 | continue; |
| 729 | | }, |
| 730 | | else => |e| return e, |
| 731 | | }; |
| 732 | | break; |
| 726 | } else |err| switch (err) { |
| 727 | error.FileNotFound => {}, |
| 728 | else => |e| return e, |
| 729 | } |
| 730 | try std.fs.rename( |
| 731 | cache_directory.handle, |
| 732 | tmp_dir_sub_path, |
| 733 | cache_directory.handle, |
| 734 | o_sub_path, |
| 735 | ); |
| 736 | break; |
| 737 | } else { |
| 738 | std.fs.rename( |
| 739 | cache_directory.handle, |
| 740 | tmp_dir_sub_path, |
| 741 | cache_directory.handle, |
| 742 | o_sub_path, |
| 743 | ) catch |err| switch (err) { |
| 744 | error.PathAlreadyExists => { |
| 745 | try cache_directory.handle.deleteTree(o_sub_path); |
| 746 | continue; |
| 747 | }, |
| 748 | else => |e| return e, |
| 749 | }; |
| 750 | break; |
| 751 | } |
| 733 | 752 | } |
| 734 | 753 | } |
| 735 | 754 | |