| author | |
| committer | |
| log | 1a455b2dd8b45fe197fcac7abb9816f5518f6ccd |
| tree | cbd0e7991fc84cb293aa22a1251592bc14e40a59 |
| parent | 396bd51c4818752f6309ff10f2d316f41598d5cd |
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.2 files changed, 16 insertions(+), 0 deletions(-)
lib/std/fs/test.zig+15| ... | ... | @@ -1434,3 +1434,18 @@ test "delete a read-only file on windows" { |
| 1434 | 1434 | file.close(); |
| 1435 | 1435 | try tmp.dir.deleteFile("test_file"); |
| 1436 | 1436 | } |
| 1437 | ||
| 1438 | test "delete a setAsCwd directory on Windows" { | |
| 1439 | if (builtin.os.tag != .windows) return error.SkipZigTest; | |
| 1440 | ||
| 1441 | var tmp = tmpDir(.{}); | |
| 1442 | // Set tmp dir as current working directory. | |
| 1443 | try tmp.dir.setAsCwd(); | |
| 1444 | tmp.dir.close(); | |
| 1445 | try testing.expectError(error.FileBusy, tmp.parent_dir.deleteTree(&tmp.sub_path)); | |
| 1446 | // Now set the parent dir as the current working dir for clean up. | |
| 1447 | try tmp.parent_dir.setAsCwd(); | |
| 1448 | try tmp.parent_dir.deleteTree(&tmp.sub_path); | |
| 1449 | // Close the parent "tmp" so we don't leak the HANDLE. | |
| 1450 | tmp.parent_dir.close(); | |
| 1451 | } |
test/standalone/windows_spawn/main.zig+1| ... | ... | @@ -116,6 +116,7 @@ pub fn main() anyerror!void { |
| 116 | 116 | |
| 117 | 117 | // Now let's set the tmp dir as the cwd and set the path only include the "something" sub dir |
| 118 | 118 | try tmp.dir.setAsCwd(); |
| 119 | defer tmp.parent_dir.setAsCwd() catch {}; | |
| 119 | 120 | const something_subdir_abs_path = try std.mem.concatWithSentinel(allocator, u16, &.{ tmp_absolute_path_w, utf16Literal("\\something") }, 0); |
| 120 | 121 | defer allocator.free(something_subdir_abs_path); |
| 121 | 122 |