Commit c8da03a0e1

Ryan Liptak <squeek502@hotmail.com>
2022-10-14 12:43:28
Fix compile error in Dir.deleteTreeMinStackSize and add test
Follow up to #13073
1 parent 9b45dc1
Changed files (2)
lib
lib/std/fs/test.zig
@@ -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
 
lib/std/fs.zig
@@ -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 {