authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-22 13:12:22-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-22 15:24:57-07:00
loge357550610aef476390ed7191eeaf7597a8e9d53
tree73b53ef2bd5cfb0fc185fc15d6ddcedd65e83eae
parent519ba9bb654a4d5caf7440160f018b7a3ae1e95a

update for the std.fs.Dir changes


11 files changed, 66 insertions(+), 57 deletions(-)

lib/std/Build/Step/InstallDir.zig+1-1
...@@ -69,7 +69,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -69,7 +69,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
69 const dest_prefix = dest_builder.getInstallPath(self.options.install_dir, self.options.install_subdir);69 const dest_prefix = dest_builder.getInstallPath(self.options.install_dir, self.options.install_subdir);
70 const src_builder = self.step.owner;70 const src_builder = self.step.owner;
71 const src_dir_path = self.options.source_dir.getPath2(src_builder, step);71 const src_dir_path = self.options.source_dir.getPath2(src_builder, step);
72 var src_dir = src_builder.build_root.handle.openIterableDir(src_dir_path, .{}) catch |err| {72 var src_dir = src_builder.build_root.handle.openDir(src_dir_path, .{ .iterate = true }) catch |err| {
73 return step.fail("unable to open source directory '{}{s}': {s}", .{73 return step.fail("unable to open source directory '{}{s}': {s}", .{
74 src_builder.build_root, src_dir_path, @errorName(err),74 src_builder.build_root, src_dir_path, @errorName(err),
75 });75 });
lib/std/child_process.zig+2-1
...@@ -976,7 +976,8 @@ fn windowsCreateProcessPathExt(...@@ -976,7 +976,8 @@ fn windowsCreateProcessPathExt(
976 defer dir_buf.shrinkRetainingCapacity(dir_path_len);976 defer dir_buf.shrinkRetainingCapacity(dir_path_len);
977 const dir_path_z = dir_buf.items[0 .. dir_buf.items.len - 1 :0];977 const dir_path_z = dir_buf.items[0 .. dir_buf.items.len - 1 :0];
978 const prefixed_path = try windows.wToPrefixedFileW(null, dir_path_z);978 const prefixed_path = try windows.wToPrefixedFileW(null, dir_path_z);
979 break :dir fs.cwd().openDirW(prefixed_path.span().ptr, .{}, true) catch return error.FileNotFound;979 break :dir fs.cwd().openDirW(prefixed_path.span().ptr, .{ .iterate = true }) catch
980 return error.FileNotFound;
980 };981 };
981 defer dir.close();982 defer dir.close();
982983
lib/std/crypto/Certificate/Bundle.zig+4-4
...@@ -160,7 +160,7 @@ pub fn addCertsFromDirPath(...@@ -160,7 +160,7 @@ pub fn addCertsFromDirPath(
160 dir: fs.Dir,160 dir: fs.Dir,
161 sub_dir_path: []const u8,161 sub_dir_path: []const u8,
162) AddCertsFromDirPathError!void {162) AddCertsFromDirPathError!void {
163 var iterable_dir = try dir.openIterableDir(sub_dir_path, .{});163 var iterable_dir = try dir.openDir(sub_dir_path, .{ .iterate = true });
164 defer iterable_dir.close();164 defer iterable_dir.close();
165 return addCertsFromDir(cb, gpa, iterable_dir);165 return addCertsFromDir(cb, gpa, iterable_dir);
166}166}
...@@ -171,14 +171,14 @@ pub fn addCertsFromDirPathAbsolute(...@@ -171,14 +171,14 @@ pub fn addCertsFromDirPathAbsolute(
171 abs_dir_path: []const u8,171 abs_dir_path: []const u8,
172) AddCertsFromDirPathError!void {172) AddCertsFromDirPathError!void {
173 assert(fs.path.isAbsolute(abs_dir_path));173 assert(fs.path.isAbsolute(abs_dir_path));
174 var iterable_dir = try fs.openIterableDirAbsolute(abs_dir_path, .{});174 var iterable_dir = try fs.openDirAbsolute(abs_dir_path, .{ .iterate = true });
175 defer iterable_dir.close();175 defer iterable_dir.close();
176 return addCertsFromDir(cb, gpa, iterable_dir);176 return addCertsFromDir(cb, gpa, iterable_dir);
177}177}
178178
179pub const AddCertsFromDirError = AddCertsFromFilePathError;179pub const AddCertsFromDirError = AddCertsFromFilePathError;
180180
181pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, iterable_dir: fs.IterableDir) AddCertsFromDirError!void {181pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, iterable_dir: fs.Dir) AddCertsFromDirError!void {
182 var it = iterable_dir.iterate();182 var it = iterable_dir.iterate();
183 while (try it.next()) |entry| {183 while (try it.next()) |entry| {
184 switch (entry.kind) {184 switch (entry.kind) {
...@@ -186,7 +186,7 @@ pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, iterable_dir: fs.IterableDir...@@ -186,7 +186,7 @@ pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, iterable_dir: fs.IterableDir
186 else => continue,186 else => continue,
187 }187 }
188188
189 try addCertsFromFilePath(cb, gpa, iterable_dir.dir, entry.name);189 try addCertsFromFilePath(cb, gpa, iterable_dir, entry.name);
190 }190 }
191}191}
192192
lib/std/fs.zig+5-5
...@@ -1653,12 +1653,12 @@ pub const Dir = struct {...@@ -1653,12 +1653,12 @@ pub const Dir = struct {
1653 pub fn openDir(self: Dir, sub_path: []const u8, args: OpenDirOptions) OpenError!Dir {1653 pub fn openDir(self: Dir, sub_path: []const u8, args: OpenDirOptions) OpenError!Dir {
1654 if (builtin.os.tag == .windows) {1654 if (builtin.os.tag == .windows) {
1655 const sub_path_w = try os.windows.sliceToPrefixedFileW(self.fd, sub_path);1655 const sub_path_w = try os.windows.sliceToPrefixedFileW(self.fd, sub_path);
1656 return .{ .dir = try self.openDirW(sub_path_w.span().ptr, args) };1656 return self.openDirW(sub_path_w.span().ptr, args);
1657 } else if (builtin.os.tag == .wasi and !builtin.link_libc) {1657 } else if (builtin.os.tag == .wasi and !builtin.link_libc) {
1658 return .{ .dir = try self.openDirWasi(sub_path, args) };1658 return self.openDirWasi(sub_path, args);
1659 } else {1659 } else {
1660 const sub_path_c = try os.toPosixPath(sub_path);1660 const sub_path_c = try os.toPosixPath(sub_path);
1661 return .{ .dir = try self.openDirZ(&sub_path_c, args) };1661 return self.openDirZ(&sub_path_c, args);
1662 }1662 }
1663 }1663 }
16641664
...@@ -2784,12 +2784,12 @@ pub fn openDirAbsolute(absolute_path: []const u8, flags: Dir.OpenDirOptions) Fil...@@ -2784,12 +2784,12 @@ pub fn openDirAbsolute(absolute_path: []const u8, flags: Dir.OpenDirOptions) Fil
2784/// Same as `openDirAbsolute` but the path parameter is null-terminated.2784/// Same as `openDirAbsolute` but the path parameter is null-terminated.
2785pub fn openDirAbsoluteZ(absolute_path_c: [*:0]const u8, flags: Dir.OpenDirOptions) File.OpenError!Dir {2785pub fn openDirAbsoluteZ(absolute_path_c: [*:0]const u8, flags: Dir.OpenDirOptions) File.OpenError!Dir {
2786 assert(path.isAbsoluteZ(absolute_path_c));2786 assert(path.isAbsoluteZ(absolute_path_c));
2787 return cwd().openDirZ(absolute_path_c, flags, false);2787 return cwd().openDirZ(absolute_path_c, flags);
2788}2788}
2789/// Same as `openDirAbsolute` but the path parameter is null-terminated.2789/// Same as `openDirAbsolute` but the path parameter is null-terminated.
2790pub fn openDirAbsoluteW(absolute_path_c: [*:0]const u16, flags: Dir.OpenDirOptions) File.OpenError!Dir {2790pub fn openDirAbsoluteW(absolute_path_c: [*:0]const u16, flags: Dir.OpenDirOptions) File.OpenError!Dir {
2791 assert(path.isAbsoluteWindowsW(absolute_path_c));2791 assert(path.isAbsoluteWindowsW(absolute_path_c));
2792 return cwd().openDirW(absolute_path_c, flags, false);2792 return cwd().openDirW(absolute_path_c, flags);
2793}2793}
27942794
2795/// Opens a file for reading or writing, without attempting to create a new file, based on an absolute path.2795/// Opens a file for reading or writing, without attempting to create a new file, based on an absolute path.
lib/std/fs/test.zig+18-20
...@@ -72,9 +72,8 @@ const PathType = enum {...@@ -72,9 +72,8 @@ const PathType = enum {
72const TestContext = struct {72const TestContext = struct {
73 path_type: PathType,73 path_type: PathType,
74 arena: ArenaAllocator,74 arena: ArenaAllocator,
75 tmp: testing.TmpIterableDir,75 tmp: testing.TmpDir,
76 dir: std.fs.Dir,76 dir: std.fs.Dir,
77 iterable_dir: std.fs.Dir,
78 transform_fn: *const PathType.TransformFn,77 transform_fn: *const PathType.TransformFn,
7978
80 pub fn init(path_type: PathType, allocator: mem.Allocator, transform_fn: *const PathType.TransformFn) TestContext {79 pub fn init(path_type: PathType, allocator: mem.Allocator, transform_fn: *const PathType.TransformFn) TestContext {
...@@ -83,8 +82,7 @@ const TestContext = struct {...@@ -83,8 +82,7 @@ const TestContext = struct {
83 .path_type = path_type,82 .path_type = path_type,
84 .arena = ArenaAllocator.init(allocator),83 .arena = ArenaAllocator.init(allocator),
85 .tmp = tmp,84 .tmp = tmp,
86 .dir = tmp.iterable_dir.dir,85 .dir = tmp.dir,
87 .iterable_dir = tmp.iterable_dir,
88 .transform_fn = transform_fn,86 .transform_fn = transform_fn,
89 };87 };
90 }88 }
...@@ -359,7 +357,7 @@ test "Dir.Iterator many entries" {...@@ -359,7 +357,7 @@ test "Dir.Iterator many entries" {
359 var buf: [4]u8 = undefined; // Enough to store "1024".357 var buf: [4]u8 = undefined; // Enough to store "1024".
360 while (i < num) : (i += 1) {358 while (i < num) : (i += 1) {
361 const name = try std.fmt.bufPrint(&buf, "{}", .{i});359 const name = try std.fmt.bufPrint(&buf, "{}", .{i});
362 const file = try tmp_dir.iterable_dir.dir.createFile(name, .{});360 const file = try tmp_dir.dir.createFile(name, .{});
363 file.close();361 file.close();
364 }362 }
365363
...@@ -370,7 +368,7 @@ test "Dir.Iterator many entries" {...@@ -370,7 +368,7 @@ test "Dir.Iterator many entries" {
370 var entries = std.ArrayList(Dir.Entry).init(allocator);368 var entries = std.ArrayList(Dir.Entry).init(allocator);
371369
372 // Create iterator.370 // Create iterator.
373 var iter = tmp_dir.iterable_dir.iterate();371 var iter = tmp_dir.dir.iterate();
374 while (try iter.next()) |entry| {372 while (try iter.next()) |entry| {
375 // We cannot just store `entry` as on Windows, we're re-using the name buffer373 // We cannot just store `entry` as on Windows, we're re-using the name buffer
376 // which means we'll actually share the `name` pointer between entries!374 // which means we'll actually share the `name` pointer between entries!
...@@ -423,17 +421,17 @@ test "Dir.Iterator reset" {...@@ -423,17 +421,17 @@ test "Dir.Iterator reset" {
423 defer tmp_dir.cleanup();421 defer tmp_dir.cleanup();
424422
425 // First, create a couple of entries to iterate over.423 // First, create a couple of entries to iterate over.
426 const file = try tmp_dir.iterable_dir.dir.createFile("some_file", .{});424 const file = try tmp_dir.dir.createFile("some_file", .{});
427 file.close();425 file.close();
428426
429 try tmp_dir.iterable_dir.dir.makeDir("some_dir");427 try tmp_dir.dir.makeDir("some_dir");
430428
431 var arena = ArenaAllocator.init(testing.allocator);429 var arena = ArenaAllocator.init(testing.allocator);
432 defer arena.deinit();430 defer arena.deinit();
433 const allocator = arena.allocator();431 const allocator = arena.allocator();
434432
435 // Create iterator.433 // Create iterator.
436 var iter = tmp_dir.iterable_dir.iterate();434 var iter = tmp_dir.dir.iterate();
437435
438 var i: u8 = 0;436 var i: u8 = 0;
439 while (i < 2) : (i += 1) {437 while (i < 2) : (i += 1) {
...@@ -459,10 +457,10 @@ test "Dir.Iterator but dir is deleted during iteration" {...@@ -459,10 +457,10 @@ test "Dir.Iterator but dir is deleted during iteration" {
459 defer tmp.cleanup();457 defer tmp.cleanup();
460458
461 // Create directory and setup an iterator for it459 // Create directory and setup an iterator for it
462 var iterable_subdir = try tmp.dir.makeOpenPathIterable("subdir", .{});460 var subdir = try tmp.dir.makeOpenPath("subdir", .{ .iterate = true });
463 defer iterable_subdir.close();461 defer subdir.close();
464462
465 var iterator = iterable_subdir.iterate();463 var iterator = subdir.iterate();
466464
467 // Create something to iterate over within the subdir465 // Create something to iterate over within the subdir
468 try tmp.dir.makePath("subdir/b");466 try tmp.dir.makePath("subdir/b");
...@@ -964,7 +962,7 @@ test "makePath in a directory that no longer exists" {...@@ -964,7 +962,7 @@ test "makePath in a directory that no longer exists" {
964fn testFilenameLimits(iterable_dir: Dir, maxed_filename: []const u8) !void {962fn testFilenameLimits(iterable_dir: Dir, maxed_filename: []const u8) !void {
965 // setup, create a dir and a nested file both with maxed filenames, and walk the dir963 // setup, create a dir and a nested file both with maxed filenames, and walk the dir
966 {964 {
967 var maxed_dir = try iterable_dir.dir.makeOpenPath(maxed_filename, .{});965 var maxed_dir = try iterable_dir.makeOpenPath(maxed_filename, .{});
968 defer maxed_dir.close();966 defer maxed_dir.close();
969967
970 try maxed_dir.writeFile(maxed_filename, "");968 try maxed_dir.writeFile(maxed_filename, "");
...@@ -981,7 +979,7 @@ fn testFilenameLimits(iterable_dir: Dir, maxed_filename: []const u8) !void {...@@ -981,7 +979,7 @@ fn testFilenameLimits(iterable_dir: Dir, maxed_filename: []const u8) !void {
981 }979 }
982980
983 // ensure that we can delete the tree981 // ensure that we can delete the tree
984 try iterable_dir.dir.deleteTree(maxed_filename);982 try iterable_dir.deleteTree(maxed_filename);
985}983}
986984
987test "max file name component lengths" {985test "max file name component lengths" {
...@@ -992,16 +990,16 @@ test "max file name component lengths" {...@@ -992,16 +990,16 @@ test "max file name component lengths" {
992 // U+FFFF is the character with the largest code point that is encoded as a single990 // U+FFFF is the character with the largest code point that is encoded as a single
993 // UTF-16 code unit, so Windows allows for NAME_MAX of them.991 // UTF-16 code unit, so Windows allows for NAME_MAX of them.
994 const maxed_windows_filename = ("\u{FFFF}".*) ** std.os.windows.NAME_MAX;992 const maxed_windows_filename = ("\u{FFFF}".*) ** std.os.windows.NAME_MAX;
995 try testFilenameLimits(tmp.iterable_dir, &maxed_windows_filename);993 try testFilenameLimits(tmp.dir, &maxed_windows_filename);
996 } else if (builtin.os.tag == .wasi) {994 } else if (builtin.os.tag == .wasi) {
997 // On WASI, the maxed filename depends on the host OS, so in order for this test to995 // On WASI, the maxed filename depends on the host OS, so in order for this test to
998 // work on any host, we need to use a length that will work for all platforms996 // work on any host, we need to use a length that will work for all platforms
999 // (i.e. the minimum MAX_NAME_BYTES of all supported platforms).997 // (i.e. the minimum MAX_NAME_BYTES of all supported platforms).
1000 const maxed_wasi_filename = [_]u8{'1'} ** 255;998 const maxed_wasi_filename = [_]u8{'1'} ** 255;
1001 try testFilenameLimits(tmp.iterable_dir, &maxed_wasi_filename);999 try testFilenameLimits(tmp.dir, &maxed_wasi_filename);
1002 } else {1000 } else {
1003 const maxed_ascii_filename = [_]u8{'1'} ** std.fs.MAX_NAME_BYTES;1001 const maxed_ascii_filename = [_]u8{'1'} ** std.fs.MAX_NAME_BYTES;
1004 try testFilenameLimits(tmp.iterable_dir, &maxed_ascii_filename);1002 try testFilenameLimits(tmp.dir, &maxed_ascii_filename);
1005 }1003 }
1006}1004}
10071005
...@@ -1438,14 +1436,14 @@ test "walker without fully iterating" {...@@ -1438,14 +1436,14 @@ test "walker without fully iterating" {
1438 var tmp = tmpDir(.{ .iterate = true });1436 var tmp = tmpDir(.{ .iterate = true });
1439 defer tmp.cleanup();1437 defer tmp.cleanup();
14401438
1441 var walker = try tmp.iterable_dir.walk(testing.allocator);1439 var walker = try tmp.dir.walk(testing.allocator);
1442 defer walker.deinit();1440 defer walker.deinit();
14431441
1444 // Create 2 directories inside the tmp directory, but then only iterate once before breaking.1442 // Create 2 directories inside the tmp directory, but then only iterate once before breaking.
1445 // This ensures that walker doesn't try to close the initial directory when not fully iterating.1443 // This ensures that walker doesn't try to close the initial directory when not fully iterating.
14461444
1447 try tmp.iterable_dir.dir.makePath("a");1445 try tmp.dir.makePath("a");
1448 try tmp.iterable_dir.dir.makePath("b");1446 try tmp.dir.makePath("b");
14491447
1450 var num_walked: usize = 0;1448 var num_walked: usize = 0;
1451 while (try walker.next()) |_| {1449 while (try walker.next()) |_| {
src/Package/Fetch.zig+14-12
...@@ -280,7 +280,7 @@ pub fn run(f: *Fetch) RunError!void {...@@ -280,7 +280,7 @@ pub fn run(f: *Fetch) RunError!void {
280 },280 },
281 .remote => |remote| remote,281 .remote => |remote| remote,
282 .path_or_url => |path_or_url| {282 .path_or_url => |path_or_url| {
283 if (fs.cwd().openIterableDir(path_or_url, .{})) |dir| {283 if (fs.cwd().openDir(path_or_url, .{ .iterate = true })) |dir| {
284 var resource: Resource = .{ .dir = dir };284 var resource: Resource = .{ .dir = dir };
285 return runResource(f, path_or_url, &resource, null);285 return runResource(f, path_or_url, &resource, null);
286 } else |dir_err| {286 } else |dir_err| {
...@@ -363,7 +363,9 @@ fn runResource(...@@ -363,7 +363,9 @@ fn runResource(
363 var tmp_directory: Cache.Directory = .{363 var tmp_directory: Cache.Directory = .{
364 .path = tmp_directory_path,364 .path = tmp_directory_path,
365 .handle = handle: {365 .handle = handle: {
366 const dir = cache_root.handle.makeOpenPathIterable(tmp_dir_sub_path, .{}) catch |err| {366 const dir = cache_root.handle.makeOpenPath(tmp_dir_sub_path, .{
367 .iterate = true,
368 }) catch |err| {
367 try eb.addRootErrorMessage(.{369 try eb.addRootErrorMessage(.{
368 .msg = try eb.printString("unable to create temporary directory '{s}': {s}", .{370 .msg = try eb.printString("unable to create temporary directory '{s}': {s}", .{
369 tmp_directory_path, @errorName(err),371 tmp_directory_path, @errorName(err),
...@@ -371,7 +373,7 @@ fn runResource(...@@ -371,7 +373,7 @@ fn runResource(
371 });373 });
372 return error.FetchFailed;374 return error.FetchFailed;
373 };375 };
374 break :handle dir.dir;376 break :handle dir;
375 },377 },
376 };378 };
377 defer tmp_directory.handle.close();379 defer tmp_directory.handle.close();
...@@ -400,9 +402,9 @@ fn runResource(...@@ -400,9 +402,9 @@ fn runResource(
400 if (builtin.os.tag == .linux and f.job_queue.work_around_btrfs_bug) {402 if (builtin.os.tag == .linux and f.job_queue.work_around_btrfs_bug) {
401 // https://github.com/ziglang/zig/issues/17095403 // https://github.com/ziglang/zig/issues/17095
402 tmp_directory.handle.close();404 tmp_directory.handle.close();
403 const iterable_dir = cache_root.handle.makeOpenPathIterable(tmp_dir_sub_path, .{}) catch405 tmp_directory.handle = cache_root.handle.makeOpenPath(tmp_dir_sub_path, .{
404 @panic("btrfs workaround failed");406 .iterate = true,
405 tmp_directory.handle = iterable_dir.dir;407 }) catch @panic("btrfs workaround failed");
406 }408 }
407409
408 f.actual_hash = try computeHash(f, tmp_directory, filter);410 f.actual_hash = try computeHash(f, tmp_directory, filter);
...@@ -717,7 +719,7 @@ const Resource = union(enum) {...@@ -717,7 +719,7 @@ const Resource = union(enum) {
717 file: fs.File,719 file: fs.File,
718 http_request: std.http.Client.Request,720 http_request: std.http.Client.Request,
719 git: Git,721 git: Git,
720 dir: fs.IterableDir,722 dir: fs.Dir,
721723
722 const Git = struct {724 const Git = struct {
723 fetch_stream: git.Session.FetchStream,725 fetch_stream: git.Session.FetchStream,
...@@ -1198,7 +1200,7 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource) anyerror!void...@@ -1198,7 +1200,7 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource) anyerror!void
1198 try out_dir.deleteTree(".git");1200 try out_dir.deleteTree(".git");
1199}1201}
12001202
1201fn recursiveDirectoryCopy(f: *Fetch, dir: fs.IterableDir, tmp_dir: fs.Dir) anyerror!void {1203fn recursiveDirectoryCopy(f: *Fetch, dir: fs.Dir, tmp_dir: fs.Dir) anyerror!void {
1202 const gpa = f.arena.child_allocator;1204 const gpa = f.arena.child_allocator;
1203 // Recursive directory copy.1205 // Recursive directory copy.
1204 var it = try dir.walk(gpa);1206 var it = try dir.walk(gpa);
...@@ -1207,7 +1209,7 @@ fn recursiveDirectoryCopy(f: *Fetch, dir: fs.IterableDir, tmp_dir: fs.Dir) anyer...@@ -1207,7 +1209,7 @@ fn recursiveDirectoryCopy(f: *Fetch, dir: fs.IterableDir, tmp_dir: fs.Dir) anyer
1207 switch (entry.kind) {1209 switch (entry.kind) {
1208 .directory => {}, // omit empty directories1210 .directory => {}, // omit empty directories
1209 .file => {1211 .file => {
1210 dir.dir.copyFile(1212 dir.copyFile(
1211 entry.path,1213 entry.path,
1212 tmp_dir,1214 tmp_dir,
1213 entry.path,1215 entry.path,
...@@ -1215,14 +1217,14 @@ fn recursiveDirectoryCopy(f: *Fetch, dir: fs.IterableDir, tmp_dir: fs.Dir) anyer...@@ -1215,14 +1217,14 @@ fn recursiveDirectoryCopy(f: *Fetch, dir: fs.IterableDir, tmp_dir: fs.Dir) anyer
1215 ) catch |err| switch (err) {1217 ) catch |err| switch (err) {
1216 error.FileNotFound => {1218 error.FileNotFound => {
1217 if (fs.path.dirname(entry.path)) |dirname| try tmp_dir.makePath(dirname);1219 if (fs.path.dirname(entry.path)) |dirname| try tmp_dir.makePath(dirname);
1218 try dir.dir.copyFile(entry.path, tmp_dir, entry.path, .{});1220 try dir.copyFile(entry.path, tmp_dir, entry.path, .{});
1219 },1221 },
1220 else => |e| return e,1222 else => |e| return e,
1221 };1223 };
1222 },1224 },
1223 .sym_link => {1225 .sym_link => {
1224 var buf: [fs.MAX_PATH_BYTES]u8 = undefined;1226 var buf: [fs.MAX_PATH_BYTES]u8 = undefined;
1225 const link_name = try dir.dir.readLink(entry.path, &buf);1227 const link_name = try dir.readLink(entry.path, &buf);
1226 // TODO: if this would create a symlink to outside1228 // TODO: if this would create a symlink to outside
1227 // the destination directory, fail with an error instead.1229 // the destination directory, fail with an error instead.
1228 tmp_dir.symLink(link_name, entry.path, .{}) catch |err| switch (err) {1230 tmp_dir.symLink(link_name, entry.path, .{}) catch |err| switch (err) {
...@@ -1296,7 +1298,7 @@ fn computeHash(...@@ -1296,7 +1298,7 @@ fn computeHash(
1296 var sus_dirs: std.StringArrayHashMapUnmanaged(void) = .{};1298 var sus_dirs: std.StringArrayHashMapUnmanaged(void) = .{};
1297 defer sus_dirs.deinit(gpa);1299 defer sus_dirs.deinit(gpa);
12981300
1299 var walker = try @as(fs.IterableDir, .{ .dir = tmp_directory.handle }).walk(gpa);1301 var walker = try tmp_directory.handle.walk(gpa);
1300 defer walker.deinit();1302 defer walker.deinit();
13011303
1302 {1304 {
src/Package/Fetch/git.zig+4-4
...@@ -1384,11 +1384,11 @@ test "packfile indexing and checkout" {...@@ -1384,11 +1384,11 @@ test "packfile indexing and checkout" {
1384 var repository = try Repository.init(testing.allocator, pack_file, index_file);1384 var repository = try Repository.init(testing.allocator, pack_file, index_file);
1385 defer repository.deinit();1385 defer repository.deinit();
13861386
1387 var worktree = testing.tmpIterableDir(.{});1387 var worktree = testing.tmpDir(.{ .iterate = true });
1388 defer worktree.cleanup();1388 defer worktree.cleanup();
13891389
1390 const commit_id = try parseOid("dd582c0720819ab7130b103635bd7271b9fd4feb");1390 const commit_id = try parseOid("dd582c0720819ab7130b103635bd7271b9fd4feb");
1391 try repository.checkout(worktree.iterable_dir.dir, commit_id);1391 try repository.checkout(worktree.dir, commit_id);
13921392
1393 const expected_files: []const []const u8 = &.{1393 const expected_files: []const []const u8 = &.{
1394 "dir/file",1394 "dir/file",
...@@ -1410,7 +1410,7 @@ test "packfile indexing and checkout" {...@@ -1410,7 +1410,7 @@ test "packfile indexing and checkout" {
1410 var actual_files: std.ArrayListUnmanaged([]u8) = .{};1410 var actual_files: std.ArrayListUnmanaged([]u8) = .{};
1411 defer actual_files.deinit(testing.allocator);1411 defer actual_files.deinit(testing.allocator);
1412 defer for (actual_files.items) |file| testing.allocator.free(file);1412 defer for (actual_files.items) |file| testing.allocator.free(file);
1413 var walker = try worktree.iterable_dir.walk(testing.allocator);1413 var walker = try worktree.dir.walk(testing.allocator);
1414 defer walker.deinit();1414 defer walker.deinit();
1415 while (try walker.next()) |entry| {1415 while (try walker.next()) |entry| {
1416 if (entry.kind != .file) continue;1416 if (entry.kind != .file) continue;
...@@ -1442,7 +1442,7 @@ test "packfile indexing and checkout" {...@@ -1442,7 +1442,7 @@ test "packfile indexing and checkout" {
1442 \\revision 191442 \\revision 19
1443 \\1443 \\
1444 ;1444 ;
1445 const actual_file_contents = try worktree.iterable_dir.dir.readFileAlloc(testing.allocator, "file", max_file_size);1445 const actual_file_contents = try worktree.dir.readFileAlloc(testing.allocator, "file", max_file_size);
1446 defer testing.allocator.free(actual_file_contents);1446 defer testing.allocator.free(actual_file_contents);
1447 try testing.expectEqualStrings(expected_file_contents, actual_file_contents);1447 try testing.expectEqualStrings(expected_file_contents, actual_file_contents);
1448}1448}
src/windows_sdk.zig+11-3
...@@ -14,7 +14,11 @@ const product_version_max_length = version_major_minor_max_length + ".65535".len...@@ -14,7 +14,11 @@ const product_version_max_length = version_major_minor_max_length + ".65535".len
14/// Iterates via `iterator` and collects all folders with names starting with `optional_prefix`14/// Iterates via `iterator` and collects all folders with names starting with `optional_prefix`
15/// and similar to SemVer. Returns slice of folder names sorted in descending order.15/// and similar to SemVer. Returns slice of folder names sorted in descending order.
16/// Caller owns result.16/// Caller owns result.
17fn iterateAndFilterBySemVer(iterator: *std.fs.IterableDir.Iterator, allocator: std.mem.Allocator, comptime optional_prefix: ?[]const u8) error{ OutOfMemory, VersionNotFound }![][]const u8 {17fn iterateAndFilterBySemVer(
18 iterator: *std.fs.Dir.Iterator,
19 allocator: std.mem.Allocator,
20 comptime optional_prefix: ?[]const u8,
21) error{ OutOfMemory, VersionNotFound }![][]const u8 {
18 var dirs_filtered_list = std.ArrayList([]const u8).init(allocator);22 var dirs_filtered_list = std.ArrayList([]const u8).init(allocator);
19 errdefer {23 errdefer {
20 for (dirs_filtered_list.items) |filtered_dir| allocator.free(filtered_dir);24 for (dirs_filtered_list.items) |filtered_dir| allocator.free(filtered_dir);
...@@ -476,7 +480,9 @@ pub const Windows81Sdk = struct {...@@ -476,7 +480,9 @@ pub const Windows81Sdk = struct {
476 if (!std.fs.path.isAbsolute(sdk_lib_dir_path)) return error.Windows81SdkNotFound;480 if (!std.fs.path.isAbsolute(sdk_lib_dir_path)) return error.Windows81SdkNotFound;
477481
478 // enumerate files in sdk path looking for latest version482 // enumerate files in sdk path looking for latest version
479 var sdk_lib_dir = std.fs.openIterableDirAbsolute(sdk_lib_dir_path, .{}) catch |err| switch (err) {483 var sdk_lib_dir = std.fs.openDirAbsolute(sdk_lib_dir_path, .{
484 .iterate = true,
485 }) catch |err| switch (err) {
480 error.NameTooLong => return error.PathTooLong,486 error.NameTooLong => return error.PathTooLong,
481 else => return error.Windows81SdkNotFound,487 else => return error.Windows81SdkNotFound,
482 };488 };
...@@ -727,7 +733,9 @@ const MsvcLibDir = struct {...@@ -727,7 +733,9 @@ const MsvcLibDir = struct {
727 if (!std.fs.path.isAbsolute(visualstudio_folder_path)) return error.PathNotFound;733 if (!std.fs.path.isAbsolute(visualstudio_folder_path)) return error.PathNotFound;
728 // enumerate folders that contain `privateregistry.bin`, looking for all versions734 // enumerate folders that contain `privateregistry.bin`, looking for all versions
729 // f.i. %localappdata%\Microsoft\VisualStudio\17.0_9e9cbb98\735 // f.i. %localappdata%\Microsoft\VisualStudio\17.0_9e9cbb98\
730 var visualstudio_folder = std.fs.openIterableDirAbsolute(visualstudio_folder_path, .{}) catch return error.PathNotFound;736 var visualstudio_folder = std.fs.openDirAbsolute(visualstudio_folder_path, .{
737 .iterate = true,
738 }) catch return error.PathNotFound;
731 defer visualstudio_folder.close();739 defer visualstudio_folder.close();
732740
733 var iterator = visualstudio_folder.iterate();741 var iterator = visualstudio_folder.iterate();
test/src/Cases.zig+5-5
...@@ -368,7 +368,7 @@ pub fn addCompile(...@@ -368,7 +368,7 @@ pub fn addCompile(
368/// Each file should include a test manifest as a contiguous block of comments at368/// Each file should include a test manifest as a contiguous block of comments at
369/// the end of the file. The first line should be the test type, followed by a set of369/// the end of the file. The first line should be the test type, followed by a set of
370/// key-value config values, followed by a blank line, then the expected output.370/// key-value config values, followed by a blank line, then the expected output.
371pub fn addFromDir(ctx: *Cases, dir: std.fs.IterableDir) void {371pub fn addFromDir(ctx: *Cases, dir: std.fs.Dir) void {
372 var current_file: []const u8 = "none";372 var current_file: []const u8 = "none";
373 ctx.addFromDirInner(dir, &current_file) catch |err| {373 ctx.addFromDirInner(dir, &current_file) catch |err| {
374 std.debug.panicExtra(374 std.debug.panicExtra(
...@@ -382,7 +382,7 @@ pub fn addFromDir(ctx: *Cases, dir: std.fs.IterableDir) void {...@@ -382,7 +382,7 @@ pub fn addFromDir(ctx: *Cases, dir: std.fs.IterableDir) void {
382382
383fn addFromDirInner(383fn addFromDirInner(
384 ctx: *Cases,384 ctx: *Cases,
385 iterable_dir: std.fs.IterableDir,385 iterable_dir: std.fs.Dir,
386 /// This is kept up to date with the currently being processed file so386 /// This is kept up to date with the currently being processed file so
387 /// that if any errors occur the caller knows it happened during this file.387 /// that if any errors occur the caller knows it happened during this file.
388 current_file: *[]const u8,388 current_file: *[]const u8,
...@@ -416,7 +416,7 @@ fn addFromDirInner(...@@ -416,7 +416,7 @@ fn addFromDirInner(
416 }416 }
417417
418 const max_file_size = 10 * 1024 * 1024;418 const max_file_size = 10 * 1024 * 1024;
419 const src = try iterable_dir.dir.readFileAllocOptions(ctx.arena, filename, max_file_size, null, 1, 0);419 const src = try iterable_dir.readFileAllocOptions(ctx.arena, filename, max_file_size, null, 1, 0);
420420
421 // Parse the manifest421 // Parse the manifest
422 var manifest = try TestManifest.parse(ctx.arena, src);422 var manifest = try TestManifest.parse(ctx.arena, src);
...@@ -1246,7 +1246,7 @@ pub fn main() !void {...@@ -1246,7 +1246,7 @@ pub fn main() !void {
1246 var filenames = std.ArrayList([]const u8).init(arena);1246 var filenames = std.ArrayList([]const u8).init(arena);
12471247
1248 const case_dirname = std.fs.path.dirname(case_file_path).?;1248 const case_dirname = std.fs.path.dirname(case_file_path).?;
1249 var iterable_dir = try std.fs.cwd().openIterableDir(case_dirname, .{});1249 var iterable_dir = try std.fs.cwd().openDir(case_dirname, .{ .iterate = true });
1250 defer iterable_dir.close();1250 defer iterable_dir.close();
12511251
1252 if (std.mem.endsWith(u8, case_file_path, ".0.zig")) {1252 if (std.mem.endsWith(u8, case_file_path, ".0.zig")) {
...@@ -1280,7 +1280,7 @@ pub fn main() !void {...@@ -1280,7 +1280,7 @@ pub fn main() !void {
12801280
1281 for (batch) |filename| {1281 for (batch) |filename| {
1282 const max_file_size = 10 * 1024 * 1024;1282 const max_file_size = 10 * 1024 * 1024;
1283 const src = try iterable_dir.dir.readFileAllocOptions(arena, filename, max_file_size, null, 1, 0);1283 const src = try iterable_dir.readFileAllocOptions(arena, filename, max_file_size, null, 1, 0);
12841284
1285 // Parse the manifest1285 // Parse the manifest
1286 var manifest = try TestManifest.parse(arena, src);1286 var manifest = try TestManifest.parse(arena, src);
test/tests.zig+1-1
...@@ -1288,7 +1288,7 @@ pub fn addCases(...@@ -1288,7 +1288,7 @@ pub fn addCases(
12881288
1289 var cases = @import("src/Cases.zig").init(gpa, arena);1289 var cases = @import("src/Cases.zig").init(gpa, arena);
12901290
1291 var dir = try b.build_root.handle.openIterableDir("test/cases", .{});1291 var dir = try b.build_root.handle.openDir("test/cases", .{ .iterate = true });
1292 defer dir.close();1292 defer dir.close();
12931293
1294 cases.addFromDir(dir);1294 cases.addFromDir(dir);
tools/generate_JSONTestSuite.zig+1-1
...@@ -18,7 +18,7 @@ pub fn main() !void {...@@ -18,7 +18,7 @@ pub fn main() !void {
18 );18 );
1919
20 var names = std.ArrayList([]const u8).init(allocator);20 var names = std.ArrayList([]const u8).init(allocator);
21 var cwd = try std.fs.cwd().openIterableDir(".", .{});21 var cwd = try std.fs.cwd().openDir(".", .{ .iterate = true });
22 var it = cwd.iterate();22 var it = cwd.iterate();
23 while (try it.next()) |entry| {23 while (try it.next()) |entry| {
24 try names.append(try allocator.dupe(u8, entry.name));24 try names.append(try allocator.dupe(u8, entry.name));