mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
fix up logic for macos std.os.deleteTree
This commit is contained in:
parent
e1e536e03d
commit
abd389209b
@ -55,7 +55,7 @@ pub fn main() !void {
|
||||
// TODO issue #709
|
||||
// disabled to pass CI tests, but obviously we want to implement this
|
||||
// and then remove this workaround
|
||||
if (builtin.os == builtin.Os.linux) {
|
||||
if (builtin.os != builtin.Os.windows) {
|
||||
os.deleteTree(allocator, tmp_dir_name) catch {};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1050,14 +1050,14 @@ const DeleteTreeError = error {
|
||||
};
|
||||
pub fn deleteTree(allocator: &Allocator, full_path: []const u8) DeleteTreeError!void {
|
||||
start_over: while (true) {
|
||||
var got_access_denied = false;
|
||||
// First, try deleting the item as a file. This way we don't follow sym links.
|
||||
if (deleteFile(allocator, full_path)) {
|
||||
return;
|
||||
} else |err| switch (err) {
|
||||
error.FileNotFound => return,
|
||||
|
||||
error.AccessDenied,
|
||||
error.IsDir => {},
|
||||
error.AccessDenied => got_access_denied = true,
|
||||
|
||||
error.OutOfMemory,
|
||||
error.SymLinkLoop,
|
||||
@ -1072,7 +1072,12 @@ pub fn deleteTree(allocator: &Allocator, full_path: []const u8) DeleteTreeError!
|
||||
}
|
||||
{
|
||||
var dir = Dir.open(allocator, full_path) catch |err| switch (err) {
|
||||
error.NotDir => continue :start_over,
|
||||
error.NotDir => {
|
||||
if (got_access_denied) {
|
||||
return error.AccessDenied;
|
||||
}
|
||||
continue :start_over;
|
||||
},
|
||||
|
||||
error.OutOfMemory,
|
||||
error.AccessDenied,
|
||||
|
||||
@ -1,18 +1,25 @@
|
||||
const std = @import("../index.zig");
|
||||
const os = std.os;
|
||||
const debug = std.debug;
|
||||
const assert = std.debug.assert;
|
||||
const io = std.io;
|
||||
|
||||
const a = std.debug.global_allocator;
|
||||
|
||||
const builtin = @import("builtin");
|
||||
|
||||
test "makePath, put some files in it, deleteTree" {
|
||||
if (builtin.os == builtin.Os.windows) {
|
||||
// TODO implement os.Dir for windows
|
||||
// https://github.com/zig-lang/zig/issues/709
|
||||
return;
|
||||
}
|
||||
try os.makePath(a, "os_test_tmp/b/c");
|
||||
try io.writeFile(a, "os_test_tmp/b/c/file.txt", "nonsense");
|
||||
try io.writeFile(a, "os_test_tmp/b/file2.txt", "blah");
|
||||
try os.deleteTree(a, "os_test_tmp");
|
||||
if (os.Dir.open(a, "os_test_tmp")) |dir| {
|
||||
debug.assert(false); // this should not happen!
|
||||
@panic("expected error");
|
||||
} else |err| {
|
||||
debug.assert(err == error.PathNotFound);
|
||||
assert(err == error.PathNotFound);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user