mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
test: Fix windows_spawn tmp directory cleanup
On Windows, a directory that's set as the current working directory is not allowed to be removed. This can cause error on `deleteTree` if the CWD is set to the file to be removed and will cause `error.FileBusy`. However, due to `tmp.cleanup()` ignoring the errors, the folder removal error will be ignored. The only test violating this is `windows_spawn`. As a solution, setting the parent directory to be the CWD before deletion will allow the cleanup to pass.
This commit is contained in:
parent
396bd51c48
commit
1a455b2dd8
2 changed files with 16 additions and 0 deletions
|
|
@ -1434,3 +1434,18 @@ test "delete a read-only file on windows" {
|
|||
file.close();
|
||||
try tmp.dir.deleteFile("test_file");
|
||||
}
|
||||
|
||||
test "delete a setAsCwd directory on Windows" {
|
||||
if (builtin.os.tag != .windows) return error.SkipZigTest;
|
||||
|
||||
var tmp = tmpDir(.{});
|
||||
// Set tmp dir as current working directory.
|
||||
try tmp.dir.setAsCwd();
|
||||
tmp.dir.close();
|
||||
try testing.expectError(error.FileBusy, tmp.parent_dir.deleteTree(&tmp.sub_path));
|
||||
// Now set the parent dir as the current working dir for clean up.
|
||||
try tmp.parent_dir.setAsCwd();
|
||||
try tmp.parent_dir.deleteTree(&tmp.sub_path);
|
||||
// Close the parent "tmp" so we don't leak the HANDLE.
|
||||
tmp.parent_dir.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ pub fn main() anyerror!void {
|
|||
|
||||
// Now let's set the tmp dir as the cwd and set the path only include the "something" sub dir
|
||||
try tmp.dir.setAsCwd();
|
||||
defer tmp.parent_dir.setAsCwd() catch {};
|
||||
const something_subdir_abs_path = try std.mem.concatWithSentinel(allocator, u16, &.{ tmp_absolute_path_w, utf16Literal("\\something") }, 0);
|
||||
defer allocator.free(something_subdir_abs_path);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue