-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5280013
commit 780690e
Showing
3 changed files
with
136 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const std = @import("std"); | ||
const builtin = std.builtin; | ||
|
||
// | ||
// TODO: we should fix std library to address these issues | ||
// | ||
pub fn deleteTree(dir: std.fs.Dir, sub_path: []const u8) !void { | ||
if (builtin.os.tag != .windows) { | ||
return dir.deleteTree(sub_path); | ||
} | ||
|
||
// workaround issue on windows where it just doesn't delete things | ||
const MAX_ATTEMPTS = 10; | ||
var attempt: u8 = 0; | ||
while (true) : (attempt += 1) { | ||
return dir.deleteTree(sub_path) catch |e| { | ||
if (attempt == MAX_ATTEMPTS) return e; | ||
switch (e) { | ||
error.FileBusy => { | ||
if (attempt == MAX_ATTEMPTS) return e; | ||
std.log.warn("path '{s}' is busy, will retry", .{sub_path}); | ||
std.time.sleep(std.time.ns_per_ms * 100); // sleep for 100 ms | ||
}, | ||
else => return e, | ||
} | ||
}; | ||
} | ||
} | ||
pub fn deleteTreeAbsolute(dir_absolute: []const u8) !void { | ||
if (builtin.os.tag != .windows) { | ||
return std.fs.deleteTreeAbsolute(dir_absolute); | ||
} | ||
std.debug.assert(std.fs.path.isAbsolute(dir_absolute)); | ||
return deleteTree(std.fs.cwd(), dir_absolute); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters