Fix compile error in Dir.deleteTreeMinStackSize and add test

Follow up to #13073
This commit is contained in:
Ryan Liptak 2022-10-14 03:43:28 -07:00 committed by Andrew Kelley
parent 9b45dc1608
commit c8da03a0e1
2 changed files with 17 additions and 1 deletions

View File

@ -2261,7 +2261,7 @@ pub const Dir = struct {
/// Like `deleteTree`, but only keeps one `Iterator` active at a time to minimize the function's stack size.
/// This is slower than `deleteTree` but uses less stack space.
pub fn deleteTreeMinStackSize(self: Dir, sub_path: []const u8) DeleteTreeError!void {
return self.deleteTreeMinStackWithKindHint(sub_path, .File);
return self.deleteTreeMinStackSizeWithKindHint(sub_path, .File);
}
fn deleteTreeMinStackSizeWithKindHint(self: Dir, sub_path: []const u8, kind_hint: File.Kind) DeleteTreeError!void {

View File

@ -677,6 +677,22 @@ test "makePath, put some files in it, deleteTree" {
}
}
test "makePath, put some files in it, deleteTreeMinStackSize" {
var tmp = tmpDir(.{});
defer tmp.cleanup();
try tmp.dir.makePath("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c");
try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense");
try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");
try tmp.dir.deleteTreeMinStackSize("os_test_tmp");
if (tmp.dir.openDir("os_test_tmp", .{})) |dir| {
_ = dir;
@panic("expected error");
} else |err| {
try testing.expect(err == error.FileNotFound);
}
}
test "makePath in a directory that no longer exists" {
if (builtin.os.tag == .windows) return error.SkipZigTest; // Windows returns FileBusy if attempting to remove an open dir