diff --git a/doc/docgen.zig b/doc/docgen.zig index 5332a62ac7..56d9a04412 100644 --- a/doc/docgen.zig +++ b/doc/docgen.zig @@ -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 {}; } } diff --git a/std/os/index.zig b/std/os/index.zig index d8e2fd7009..4b74af035e 100644 --- a/std/os/index.zig +++ b/std/os/index.zig @@ -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, diff --git a/std/os/test.zig b/std/os/test.zig index 20d439cc48..9c718d5b6b 100644 --- a/std/os/test.zig +++ b/std/os/test.zig @@ -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); } }