update for the std.fs.Dir changes

This commit is contained in:
Andrew Kelley 2023-11-22 13:12:22 -07:00
parent 519ba9bb65
commit e357550610
11 changed files with 66 additions and 57 deletions

View File

@ -69,7 +69,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
const dest_prefix = dest_builder.getInstallPath(self.options.install_dir, self.options.install_subdir); const dest_prefix = dest_builder.getInstallPath(self.options.install_dir, self.options.install_subdir);
const src_builder = self.step.owner; const src_builder = self.step.owner;
const src_dir_path = self.options.source_dir.getPath2(src_builder, step); const src_dir_path = self.options.source_dir.getPath2(src_builder, step);
var src_dir = src_builder.build_root.handle.openIterableDir(src_dir_path, .{}) catch |err| { var src_dir = src_builder.build_root.handle.openDir(src_dir_path, .{ .iterate = true }) catch |err| {
return step.fail("unable to open source directory '{}{s}': {s}", .{ return step.fail("unable to open source directory '{}{s}': {s}", .{
src_builder.build_root, src_dir_path, @errorName(err), src_builder.build_root, src_dir_path, @errorName(err),
}); });

View File

@ -976,7 +976,8 @@ fn windowsCreateProcessPathExt(
defer dir_buf.shrinkRetainingCapacity(dir_path_len); defer dir_buf.shrinkRetainingCapacity(dir_path_len);
const dir_path_z = dir_buf.items[0 .. dir_buf.items.len - 1 :0]; const dir_path_z = dir_buf.items[0 .. dir_buf.items.len - 1 :0];
const prefixed_path = try windows.wToPrefixedFileW(null, dir_path_z); const prefixed_path = try windows.wToPrefixedFileW(null, dir_path_z);
break :dir fs.cwd().openDirW(prefixed_path.span().ptr, .{}, true) catch return error.FileNotFound; break :dir fs.cwd().openDirW(prefixed_path.span().ptr, .{ .iterate = true }) catch
return error.FileNotFound;
}; };
defer dir.close(); defer dir.close();

View File

@ -160,7 +160,7 @@ pub fn addCertsFromDirPath(
dir: fs.Dir, dir: fs.Dir,
sub_dir_path: []const u8, sub_dir_path: []const u8,
) AddCertsFromDirPathError!void { ) AddCertsFromDirPathError!void {
var iterable_dir = try dir.openIterableDir(sub_dir_path, .{}); var iterable_dir = try dir.openDir(sub_dir_path, .{ .iterate = true });
defer iterable_dir.close(); defer iterable_dir.close();
return addCertsFromDir(cb, gpa, iterable_dir); return addCertsFromDir(cb, gpa, iterable_dir);
} }
@ -171,14 +171,14 @@ pub fn addCertsFromDirPathAbsolute(
abs_dir_path: []const u8, abs_dir_path: []const u8,
) AddCertsFromDirPathError!void { ) AddCertsFromDirPathError!void {
assert(fs.path.isAbsolute(abs_dir_path)); assert(fs.path.isAbsolute(abs_dir_path));
var iterable_dir = try fs.openIterableDirAbsolute(abs_dir_path, .{}); var iterable_dir = try fs.openDirAbsolute(abs_dir_path, .{ .iterate = true });
defer iterable_dir.close(); defer iterable_dir.close();
return addCertsFromDir(cb, gpa, iterable_dir); return addCertsFromDir(cb, gpa, iterable_dir);
} }
pub const AddCertsFromDirError = AddCertsFromFilePathError; pub const AddCertsFromDirError = AddCertsFromFilePathError;
pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, iterable_dir: fs.IterableDir) AddCertsFromDirError!void { pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, iterable_dir: fs.Dir) AddCertsFromDirError!void {
var it = iterable_dir.iterate(); var it = iterable_dir.iterate();
while (try it.next()) |entry| { while (try it.next()) |entry| {
switch (entry.kind) { switch (entry.kind) {
@ -186,7 +186,7 @@ pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, iterable_dir: fs.IterableDir
else => continue, else => continue,
} }
try addCertsFromFilePath(cb, gpa, iterable_dir.dir, entry.name); try addCertsFromFilePath(cb, gpa, iterable_dir, entry.name);
} }
} }

View File

@ -1653,12 +1653,12 @@ pub const Dir = struct {
pub fn openDir(self: Dir, sub_path: []const u8, args: OpenDirOptions) OpenError!Dir { pub fn openDir(self: Dir, sub_path: []const u8, args: OpenDirOptions) OpenError!Dir {
if (builtin.os.tag == .windows) { if (builtin.os.tag == .windows) {
const sub_path_w = try os.windows.sliceToPrefixedFileW(self.fd, sub_path); const sub_path_w = try os.windows.sliceToPrefixedFileW(self.fd, sub_path);
return .{ .dir = try self.openDirW(sub_path_w.span().ptr, args) }; return self.openDirW(sub_path_w.span().ptr, args);
} else if (builtin.os.tag == .wasi and !builtin.link_libc) { } else if (builtin.os.tag == .wasi and !builtin.link_libc) {
return .{ .dir = try self.openDirWasi(sub_path, args) }; return self.openDirWasi(sub_path, args);
} else { } else {
const sub_path_c = try os.toPosixPath(sub_path); const sub_path_c = try os.toPosixPath(sub_path);
return .{ .dir = try self.openDirZ(&sub_path_c, args) }; return self.openDirZ(&sub_path_c, args);
} }
} }
@ -2784,12 +2784,12 @@ pub fn openDirAbsolute(absolute_path: []const u8, flags: Dir.OpenDirOptions) Fil
/// Same as `openDirAbsolute` but the path parameter is null-terminated. /// Same as `openDirAbsolute` but the path parameter is null-terminated.
pub fn openDirAbsoluteZ(absolute_path_c: [*:0]const u8, flags: Dir.OpenDirOptions) File.OpenError!Dir { pub fn openDirAbsoluteZ(absolute_path_c: [*:0]const u8, flags: Dir.OpenDirOptions) File.OpenError!Dir {
assert(path.isAbsoluteZ(absolute_path_c)); assert(path.isAbsoluteZ(absolute_path_c));
return cwd().openDirZ(absolute_path_c, flags, false); return cwd().openDirZ(absolute_path_c, flags);
} }
/// Same as `openDirAbsolute` but the path parameter is null-terminated. /// Same as `openDirAbsolute` but the path parameter is null-terminated.
pub fn openDirAbsoluteW(absolute_path_c: [*:0]const u16, flags: Dir.OpenDirOptions) File.OpenError!Dir { pub fn openDirAbsoluteW(absolute_path_c: [*:0]const u16, flags: Dir.OpenDirOptions) File.OpenError!Dir {
assert(path.isAbsoluteWindowsW(absolute_path_c)); assert(path.isAbsoluteWindowsW(absolute_path_c));
return cwd().openDirW(absolute_path_c, flags, false); return cwd().openDirW(absolute_path_c, flags);
} }
/// Opens a file for reading or writing, without attempting to create a new file, based on an absolute path. /// Opens a file for reading or writing, without attempting to create a new file, based on an absolute path.

View File

@ -72,9 +72,8 @@ const PathType = enum {
const TestContext = struct { const TestContext = struct {
path_type: PathType, path_type: PathType,
arena: ArenaAllocator, arena: ArenaAllocator,
tmp: testing.TmpIterableDir, tmp: testing.TmpDir,
dir: std.fs.Dir, dir: std.fs.Dir,
iterable_dir: std.fs.Dir,
transform_fn: *const PathType.TransformFn, transform_fn: *const PathType.TransformFn,
pub fn init(path_type: PathType, allocator: mem.Allocator, transform_fn: *const PathType.TransformFn) TestContext { pub fn init(path_type: PathType, allocator: mem.Allocator, transform_fn: *const PathType.TransformFn) TestContext {
@ -83,8 +82,7 @@ const TestContext = struct {
.path_type = path_type, .path_type = path_type,
.arena = ArenaAllocator.init(allocator), .arena = ArenaAllocator.init(allocator),
.tmp = tmp, .tmp = tmp,
.dir = tmp.iterable_dir.dir, .dir = tmp.dir,
.iterable_dir = tmp.iterable_dir,
.transform_fn = transform_fn, .transform_fn = transform_fn,
}; };
} }
@ -359,7 +357,7 @@ test "Dir.Iterator many entries" {
var buf: [4]u8 = undefined; // Enough to store "1024". var buf: [4]u8 = undefined; // Enough to store "1024".
while (i < num) : (i += 1) { while (i < num) : (i += 1) {
const name = try std.fmt.bufPrint(&buf, "{}", .{i}); const name = try std.fmt.bufPrint(&buf, "{}", .{i});
const file = try tmp_dir.iterable_dir.dir.createFile(name, .{}); const file = try tmp_dir.dir.createFile(name, .{});
file.close(); file.close();
} }
@ -370,7 +368,7 @@ test "Dir.Iterator many entries" {
var entries = std.ArrayList(Dir.Entry).init(allocator); var entries = std.ArrayList(Dir.Entry).init(allocator);
// Create iterator. // Create iterator.
var iter = tmp_dir.iterable_dir.iterate(); var iter = tmp_dir.dir.iterate();
while (try iter.next()) |entry| { while (try iter.next()) |entry| {
// We cannot just store `entry` as on Windows, we're re-using the name buffer // We cannot just store `entry` as on Windows, we're re-using the name buffer
// which means we'll actually share the `name` pointer between entries! // which means we'll actually share the `name` pointer between entries!
@ -423,17 +421,17 @@ test "Dir.Iterator reset" {
defer tmp_dir.cleanup(); defer tmp_dir.cleanup();
// First, create a couple of entries to iterate over. // First, create a couple of entries to iterate over.
const file = try tmp_dir.iterable_dir.dir.createFile("some_file", .{}); const file = try tmp_dir.dir.createFile("some_file", .{});
file.close(); file.close();
try tmp_dir.iterable_dir.dir.makeDir("some_dir"); try tmp_dir.dir.makeDir("some_dir");
var arena = ArenaAllocator.init(testing.allocator); var arena = ArenaAllocator.init(testing.allocator);
defer arena.deinit(); defer arena.deinit();
const allocator = arena.allocator(); const allocator = arena.allocator();
// Create iterator. // Create iterator.
var iter = tmp_dir.iterable_dir.iterate(); var iter = tmp_dir.dir.iterate();
var i: u8 = 0; var i: u8 = 0;
while (i < 2) : (i += 1) { while (i < 2) : (i += 1) {
@ -459,10 +457,10 @@ test "Dir.Iterator but dir is deleted during iteration" {
defer tmp.cleanup(); defer tmp.cleanup();
// Create directory and setup an iterator for it // Create directory and setup an iterator for it
var iterable_subdir = try tmp.dir.makeOpenPathIterable("subdir", .{}); var subdir = try tmp.dir.makeOpenPath("subdir", .{ .iterate = true });
defer iterable_subdir.close(); defer subdir.close();
var iterator = iterable_subdir.iterate(); var iterator = subdir.iterate();
// Create something to iterate over within the subdir // Create something to iterate over within the subdir
try tmp.dir.makePath("subdir/b"); try tmp.dir.makePath("subdir/b");
@ -964,7 +962,7 @@ test "makePath in a directory that no longer exists" {
fn testFilenameLimits(iterable_dir: Dir, maxed_filename: []const u8) !void { fn testFilenameLimits(iterable_dir: Dir, maxed_filename: []const u8) !void {
// setup, create a dir and a nested file both with maxed filenames, and walk the dir // setup, create a dir and a nested file both with maxed filenames, and walk the dir
{ {
var maxed_dir = try iterable_dir.dir.makeOpenPath(maxed_filename, .{}); var maxed_dir = try iterable_dir.makeOpenPath(maxed_filename, .{});
defer maxed_dir.close(); defer maxed_dir.close();
try maxed_dir.writeFile(maxed_filename, ""); try maxed_dir.writeFile(maxed_filename, "");
@ -981,7 +979,7 @@ fn testFilenameLimits(iterable_dir: Dir, maxed_filename: []const u8) !void {
} }
// ensure that we can delete the tree // ensure that we can delete the tree
try iterable_dir.dir.deleteTree(maxed_filename); try iterable_dir.deleteTree(maxed_filename);
} }
test "max file name component lengths" { test "max file name component lengths" {
@ -992,16 +990,16 @@ test "max file name component lengths" {
// U+FFFF is the character with the largest code point that is encoded as a single // U+FFFF is the character with the largest code point that is encoded as a single
// UTF-16 code unit, so Windows allows for NAME_MAX of them. // UTF-16 code unit, so Windows allows for NAME_MAX of them.
const maxed_windows_filename = ("\u{FFFF}".*) ** std.os.windows.NAME_MAX; const maxed_windows_filename = ("\u{FFFF}".*) ** std.os.windows.NAME_MAX;
try testFilenameLimits(tmp.iterable_dir, &maxed_windows_filename); try testFilenameLimits(tmp.dir, &maxed_windows_filename);
} else if (builtin.os.tag == .wasi) { } else if (builtin.os.tag == .wasi) {
// On WASI, the maxed filename depends on the host OS, so in order for this test to // On WASI, the maxed filename depends on the host OS, so in order for this test to
// work on any host, we need to use a length that will work for all platforms // work on any host, we need to use a length that will work for all platforms
// (i.e. the minimum MAX_NAME_BYTES of all supported platforms). // (i.e. the minimum MAX_NAME_BYTES of all supported platforms).
const maxed_wasi_filename = [_]u8{'1'} ** 255; const maxed_wasi_filename = [_]u8{'1'} ** 255;
try testFilenameLimits(tmp.iterable_dir, &maxed_wasi_filename); try testFilenameLimits(tmp.dir, &maxed_wasi_filename);
} else { } else {
const maxed_ascii_filename = [_]u8{'1'} ** std.fs.MAX_NAME_BYTES; const maxed_ascii_filename = [_]u8{'1'} ** std.fs.MAX_NAME_BYTES;
try testFilenameLimits(tmp.iterable_dir, &maxed_ascii_filename); try testFilenameLimits(tmp.dir, &maxed_ascii_filename);
} }
} }
@ -1438,14 +1436,14 @@ test "walker without fully iterating" {
var tmp = tmpDir(.{ .iterate = true }); var tmp = tmpDir(.{ .iterate = true });
defer tmp.cleanup(); defer tmp.cleanup();
var walker = try tmp.iterable_dir.walk(testing.allocator); var walker = try tmp.dir.walk(testing.allocator);
defer walker.deinit(); defer walker.deinit();
// Create 2 directories inside the tmp directory, but then only iterate once before breaking. // Create 2 directories inside the tmp directory, but then only iterate once before breaking.
// This ensures that walker doesn't try to close the initial directory when not fully iterating. // This ensures that walker doesn't try to close the initial directory when not fully iterating.
try tmp.iterable_dir.dir.makePath("a"); try tmp.dir.makePath("a");
try tmp.iterable_dir.dir.makePath("b"); try tmp.dir.makePath("b");
var num_walked: usize = 0; var num_walked: usize = 0;
while (try walker.next()) |_| { while (try walker.next()) |_| {

View File

@ -280,7 +280,7 @@ pub fn run(f: *Fetch) RunError!void {
}, },
.remote => |remote| remote, .remote => |remote| remote,
.path_or_url => |path_or_url| { .path_or_url => |path_or_url| {
if (fs.cwd().openIterableDir(path_or_url, .{})) |dir| { if (fs.cwd().openDir(path_or_url, .{ .iterate = true })) |dir| {
var resource: Resource = .{ .dir = dir }; var resource: Resource = .{ .dir = dir };
return runResource(f, path_or_url, &resource, null); return runResource(f, path_or_url, &resource, null);
} else |dir_err| { } else |dir_err| {
@ -363,7 +363,9 @@ fn runResource(
var tmp_directory: Cache.Directory = .{ var tmp_directory: Cache.Directory = .{
.path = tmp_directory_path, .path = tmp_directory_path,
.handle = handle: { .handle = handle: {
const dir = cache_root.handle.makeOpenPathIterable(tmp_dir_sub_path, .{}) catch |err| { const dir = cache_root.handle.makeOpenPath(tmp_dir_sub_path, .{
.iterate = true,
}) catch |err| {
try eb.addRootErrorMessage(.{ try eb.addRootErrorMessage(.{
.msg = try eb.printString("unable to create temporary directory '{s}': {s}", .{ .msg = try eb.printString("unable to create temporary directory '{s}': {s}", .{
tmp_directory_path, @errorName(err), tmp_directory_path, @errorName(err),
@ -371,7 +373,7 @@ fn runResource(
}); });
return error.FetchFailed; return error.FetchFailed;
}; };
break :handle dir.dir; break :handle dir;
}, },
}; };
defer tmp_directory.handle.close(); defer tmp_directory.handle.close();
@ -400,9 +402,9 @@ fn runResource(
if (builtin.os.tag == .linux and f.job_queue.work_around_btrfs_bug) { if (builtin.os.tag == .linux and f.job_queue.work_around_btrfs_bug) {
// https://github.com/ziglang/zig/issues/17095 // https://github.com/ziglang/zig/issues/17095
tmp_directory.handle.close(); tmp_directory.handle.close();
const iterable_dir = cache_root.handle.makeOpenPathIterable(tmp_dir_sub_path, .{}) catch tmp_directory.handle = cache_root.handle.makeOpenPath(tmp_dir_sub_path, .{
@panic("btrfs workaround failed"); .iterate = true,
tmp_directory.handle = iterable_dir.dir; }) catch @panic("btrfs workaround failed");
} }
f.actual_hash = try computeHash(f, tmp_directory, filter); f.actual_hash = try computeHash(f, tmp_directory, filter);
@ -717,7 +719,7 @@ const Resource = union(enum) {
file: fs.File, file: fs.File,
http_request: std.http.Client.Request, http_request: std.http.Client.Request,
git: Git, git: Git,
dir: fs.IterableDir, dir: fs.Dir,
const Git = struct { const Git = struct {
fetch_stream: git.Session.FetchStream, fetch_stream: git.Session.FetchStream,
@ -1198,7 +1200,7 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource) anyerror!void
try out_dir.deleteTree(".git"); try out_dir.deleteTree(".git");
} }
fn recursiveDirectoryCopy(f: *Fetch, dir: fs.IterableDir, tmp_dir: fs.Dir) anyerror!void { fn recursiveDirectoryCopy(f: *Fetch, dir: fs.Dir, tmp_dir: fs.Dir) anyerror!void {
const gpa = f.arena.child_allocator; const gpa = f.arena.child_allocator;
// Recursive directory copy. // Recursive directory copy.
var it = try dir.walk(gpa); var it = try dir.walk(gpa);
@ -1207,7 +1209,7 @@ fn recursiveDirectoryCopy(f: *Fetch, dir: fs.IterableDir, tmp_dir: fs.Dir) anyer
switch (entry.kind) { switch (entry.kind) {
.directory => {}, // omit empty directories .directory => {}, // omit empty directories
.file => { .file => {
dir.dir.copyFile( dir.copyFile(
entry.path, entry.path,
tmp_dir, tmp_dir,
entry.path, entry.path,
@ -1215,14 +1217,14 @@ fn recursiveDirectoryCopy(f: *Fetch, dir: fs.IterableDir, tmp_dir: fs.Dir) anyer
) catch |err| switch (err) { ) catch |err| switch (err) {
error.FileNotFound => { error.FileNotFound => {
if (fs.path.dirname(entry.path)) |dirname| try tmp_dir.makePath(dirname); if (fs.path.dirname(entry.path)) |dirname| try tmp_dir.makePath(dirname);
try dir.dir.copyFile(entry.path, tmp_dir, entry.path, .{}); try dir.copyFile(entry.path, tmp_dir, entry.path, .{});
}, },
else => |e| return e, else => |e| return e,
}; };
}, },
.sym_link => { .sym_link => {
var buf: [fs.MAX_PATH_BYTES]u8 = undefined; var buf: [fs.MAX_PATH_BYTES]u8 = undefined;
const link_name = try dir.dir.readLink(entry.path, &buf); const link_name = try dir.readLink(entry.path, &buf);
// TODO: if this would create a symlink to outside // TODO: if this would create a symlink to outside
// the destination directory, fail with an error instead. // the destination directory, fail with an error instead.
tmp_dir.symLink(link_name, entry.path, .{}) catch |err| switch (err) { tmp_dir.symLink(link_name, entry.path, .{}) catch |err| switch (err) {
@ -1296,7 +1298,7 @@ fn computeHash(
var sus_dirs: std.StringArrayHashMapUnmanaged(void) = .{}; var sus_dirs: std.StringArrayHashMapUnmanaged(void) = .{};
defer sus_dirs.deinit(gpa); defer sus_dirs.deinit(gpa);
var walker = try @as(fs.IterableDir, .{ .dir = tmp_directory.handle }).walk(gpa); var walker = try tmp_directory.handle.walk(gpa);
defer walker.deinit(); defer walker.deinit();
{ {

View File

@ -1384,11 +1384,11 @@ test "packfile indexing and checkout" {
var repository = try Repository.init(testing.allocator, pack_file, index_file); var repository = try Repository.init(testing.allocator, pack_file, index_file);
defer repository.deinit(); defer repository.deinit();
var worktree = testing.tmpIterableDir(.{}); var worktree = testing.tmpDir(.{ .iterate = true });
defer worktree.cleanup(); defer worktree.cleanup();
const commit_id = try parseOid("dd582c0720819ab7130b103635bd7271b9fd4feb"); const commit_id = try parseOid("dd582c0720819ab7130b103635bd7271b9fd4feb");
try repository.checkout(worktree.iterable_dir.dir, commit_id); try repository.checkout(worktree.dir, commit_id);
const expected_files: []const []const u8 = &.{ const expected_files: []const []const u8 = &.{
"dir/file", "dir/file",
@ -1410,7 +1410,7 @@ test "packfile indexing and checkout" {
var actual_files: std.ArrayListUnmanaged([]u8) = .{}; var actual_files: std.ArrayListUnmanaged([]u8) = .{};
defer actual_files.deinit(testing.allocator); defer actual_files.deinit(testing.allocator);
defer for (actual_files.items) |file| testing.allocator.free(file); defer for (actual_files.items) |file| testing.allocator.free(file);
var walker = try worktree.iterable_dir.walk(testing.allocator); var walker = try worktree.dir.walk(testing.allocator);
defer walker.deinit(); defer walker.deinit();
while (try walker.next()) |entry| { while (try walker.next()) |entry| {
if (entry.kind != .file) continue; if (entry.kind != .file) continue;
@ -1442,7 +1442,7 @@ test "packfile indexing and checkout" {
\\revision 19 \\revision 19
\\ \\
; ;
const actual_file_contents = try worktree.iterable_dir.dir.readFileAlloc(testing.allocator, "file", max_file_size); const actual_file_contents = try worktree.dir.readFileAlloc(testing.allocator, "file", max_file_size);
defer testing.allocator.free(actual_file_contents); defer testing.allocator.free(actual_file_contents);
try testing.expectEqualStrings(expected_file_contents, actual_file_contents); try testing.expectEqualStrings(expected_file_contents, actual_file_contents);
} }

View File

@ -14,7 +14,11 @@ const product_version_max_length = version_major_minor_max_length + ".65535".len
/// Iterates via `iterator` and collects all folders with names starting with `optional_prefix` /// Iterates via `iterator` and collects all folders with names starting with `optional_prefix`
/// and similar to SemVer. Returns slice of folder names sorted in descending order. /// and similar to SemVer. Returns slice of folder names sorted in descending order.
/// Caller owns result. /// Caller owns result.
fn iterateAndFilterBySemVer(iterator: *std.fs.IterableDir.Iterator, allocator: std.mem.Allocator, comptime optional_prefix: ?[]const u8) error{ OutOfMemory, VersionNotFound }![][]const u8 { fn iterateAndFilterBySemVer(
iterator: *std.fs.Dir.Iterator,
allocator: std.mem.Allocator,
comptime optional_prefix: ?[]const u8,
) error{ OutOfMemory, VersionNotFound }![][]const u8 {
var dirs_filtered_list = std.ArrayList([]const u8).init(allocator); var dirs_filtered_list = std.ArrayList([]const u8).init(allocator);
errdefer { errdefer {
for (dirs_filtered_list.items) |filtered_dir| allocator.free(filtered_dir); for (dirs_filtered_list.items) |filtered_dir| allocator.free(filtered_dir);
@ -476,7 +480,9 @@ pub const Windows81Sdk = struct {
if (!std.fs.path.isAbsolute(sdk_lib_dir_path)) return error.Windows81SdkNotFound; if (!std.fs.path.isAbsolute(sdk_lib_dir_path)) return error.Windows81SdkNotFound;
// enumerate files in sdk path looking for latest version // enumerate files in sdk path looking for latest version
var sdk_lib_dir = std.fs.openIterableDirAbsolute(sdk_lib_dir_path, .{}) catch |err| switch (err) { var sdk_lib_dir = std.fs.openDirAbsolute(sdk_lib_dir_path, .{
.iterate = true,
}) catch |err| switch (err) {
error.NameTooLong => return error.PathTooLong, error.NameTooLong => return error.PathTooLong,
else => return error.Windows81SdkNotFound, else => return error.Windows81SdkNotFound,
}; };
@ -727,7 +733,9 @@ const MsvcLibDir = struct {
if (!std.fs.path.isAbsolute(visualstudio_folder_path)) return error.PathNotFound; if (!std.fs.path.isAbsolute(visualstudio_folder_path)) return error.PathNotFound;
// enumerate folders that contain `privateregistry.bin`, looking for all versions // enumerate folders that contain `privateregistry.bin`, looking for all versions
// f.i. %localappdata%\Microsoft\VisualStudio\17.0_9e9cbb98\ // f.i. %localappdata%\Microsoft\VisualStudio\17.0_9e9cbb98\
var visualstudio_folder = std.fs.openIterableDirAbsolute(visualstudio_folder_path, .{}) catch return error.PathNotFound; var visualstudio_folder = std.fs.openDirAbsolute(visualstudio_folder_path, .{
.iterate = true,
}) catch return error.PathNotFound;
defer visualstudio_folder.close(); defer visualstudio_folder.close();
var iterator = visualstudio_folder.iterate(); var iterator = visualstudio_folder.iterate();

View File

@ -368,7 +368,7 @@ pub fn addCompile(
/// Each file should include a test manifest as a contiguous block of comments at /// Each file should include a test manifest as a contiguous block of comments at
/// the end of the file. The first line should be the test type, followed by a set of /// the end of the file. The first line should be the test type, followed by a set of
/// key-value config values, followed by a blank line, then the expected output. /// key-value config values, followed by a blank line, then the expected output.
pub fn addFromDir(ctx: *Cases, dir: std.fs.IterableDir) void { pub fn addFromDir(ctx: *Cases, dir: std.fs.Dir) void {
var current_file: []const u8 = "none"; var current_file: []const u8 = "none";
ctx.addFromDirInner(dir, &current_file) catch |err| { ctx.addFromDirInner(dir, &current_file) catch |err| {
std.debug.panicExtra( std.debug.panicExtra(
@ -382,7 +382,7 @@ pub fn addFromDir(ctx: *Cases, dir: std.fs.IterableDir) void {
fn addFromDirInner( fn addFromDirInner(
ctx: *Cases, ctx: *Cases,
iterable_dir: std.fs.IterableDir, iterable_dir: std.fs.Dir,
/// This is kept up to date with the currently being processed file so /// This is kept up to date with the currently being processed file so
/// that if any errors occur the caller knows it happened during this file. /// that if any errors occur the caller knows it happened during this file.
current_file: *[]const u8, current_file: *[]const u8,
@ -416,7 +416,7 @@ fn addFromDirInner(
} }
const max_file_size = 10 * 1024 * 1024; const max_file_size = 10 * 1024 * 1024;
const src = try iterable_dir.dir.readFileAllocOptions(ctx.arena, filename, max_file_size, null, 1, 0); const src = try iterable_dir.readFileAllocOptions(ctx.arena, filename, max_file_size, null, 1, 0);
// Parse the manifest // Parse the manifest
var manifest = try TestManifest.parse(ctx.arena, src); var manifest = try TestManifest.parse(ctx.arena, src);
@ -1246,7 +1246,7 @@ pub fn main() !void {
var filenames = std.ArrayList([]const u8).init(arena); var filenames = std.ArrayList([]const u8).init(arena);
const case_dirname = std.fs.path.dirname(case_file_path).?; const case_dirname = std.fs.path.dirname(case_file_path).?;
var iterable_dir = try std.fs.cwd().openIterableDir(case_dirname, .{}); var iterable_dir = try std.fs.cwd().openDir(case_dirname, .{ .iterate = true });
defer iterable_dir.close(); defer iterable_dir.close();
if (std.mem.endsWith(u8, case_file_path, ".0.zig")) { if (std.mem.endsWith(u8, case_file_path, ".0.zig")) {
@ -1280,7 +1280,7 @@ pub fn main() !void {
for (batch) |filename| { for (batch) |filename| {
const max_file_size = 10 * 1024 * 1024; const max_file_size = 10 * 1024 * 1024;
const src = try iterable_dir.dir.readFileAllocOptions(arena, filename, max_file_size, null, 1, 0); const src = try iterable_dir.readFileAllocOptions(arena, filename, max_file_size, null, 1, 0);
// Parse the manifest // Parse the manifest
var manifest = try TestManifest.parse(arena, src); var manifest = try TestManifest.parse(arena, src);

View File

@ -1288,7 +1288,7 @@ pub fn addCases(
var cases = @import("src/Cases.zig").init(gpa, arena); var cases = @import("src/Cases.zig").init(gpa, arena);
var dir = try b.build_root.handle.openIterableDir("test/cases", .{}); var dir = try b.build_root.handle.openDir("test/cases", .{ .iterate = true });
defer dir.close(); defer dir.close();
cases.addFromDir(dir); cases.addFromDir(dir);

View File

@ -18,7 +18,7 @@ pub fn main() !void {
); );
var names = std.ArrayList([]const u8).init(allocator); var names = std.ArrayList([]const u8).init(allocator);
var cwd = try std.fs.cwd().openIterableDir(".", .{}); var cwd = try std.fs.cwd().openDir(".", .{ .iterate = true });
var it = cwd.iterate(); var it = cwd.iterate();
while (try it.next()) |entry| { while (try it.next()) |entry| {
try names.append(try allocator.dupe(u8, entry.name)); try names.append(try allocator.dupe(u8, entry.name));