| author | |
| committer | |
| log | 618398b7d3c0df13dcb3d87540e400665b2c02dc |
| tree | 3bd67392b54ffcbc38ed178bbff0119abdce1811 |
| parent | d66c61a2cf69665223815a1a12a1f93b30b99571 |
The call to `makeDir` for the top-level component of `sub_path`
can return `error.FileNotFound` if the directory represented by
`self` has been deleted.
Fixes #113972 files changed, 11 insertions(+), 1 deletions(-)
lib/std/fs.zig+1-1| ... | ... | @@ -1308,9 +1308,9 @@ pub const Dir = struct { |
| 1308 | 1308 | if (end_index == sub_path.len) return; |
| 1309 | 1309 | }, |
| 1310 | 1310 | error.FileNotFound => { |
| 1311 | if (end_index == 0) return err; | |
| 1312 | 1311 | // march end_index backward until next path component |
| 1313 | 1312 | while (true) { |
| 1313 | if (end_index == 0) return err; | |
| 1314 | 1314 | end_index -= 1; |
| 1315 | 1315 | if (path.isSep(sub_path[end_index])) break; |
| 1316 | 1316 | } |
lib/std/fs/test.zig+10| ... | ... | @@ -610,6 +610,16 @@ test "makePath, put some files in it, deleteTree" { |
| 610 | 610 | } |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | test "makePath in a directory that no longer exists" { | |
| 614 | if (builtin.os.tag == .windows) return error.SkipZigTest; // Windows returns FileBusy if attempting to remove an open dir | |
| 615 | ||
| 616 | var tmp = tmpDir(.{}); | |
| 617 | defer tmp.cleanup(); | |
| 618 | try tmp.parent_dir.deleteTree(&tmp.sub_path); | |
| 619 | ||
| 620 | try testing.expectError(error.FileNotFound, tmp.dir.makePath("sub-path")); | |
| 621 | } | |
| 622 | ||
| 613 | 623 | test "writev, readv" { |
| 614 | 624 | var tmp = tmpDir(.{}); |
| 615 | 625 | defer tmp.cleanup(); |