aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-12-08 13:46:29 -0800
committerAndrew Kelley <andrew@ziglang.org>2025-12-23 22:15:08 -0800
commit264d714321d3e5f1f189af393e1fb24d101a7e91 (patch)
treecb637a9c8c8565790db5b8cbcd1e960f88523da1 /lib/std
parentf53248a40936ebc9aaf75ddbd16e67ebec05ab84 (diff)
downloadzig-264d714321d3e5f1f189af393e1fb24d101a7e91.tar.gz
zig-264d714321d3e5f1f189af393e1fb24d101a7e91.zip
update all openDir() sites to accept io instance
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/Build.zig3
-rw-r--r--lib/std/Build/Cache/Path.zig3
-rw-r--r--lib/std/Build/Step/InstallArtifact.zig2
-rw-r--r--lib/std/Build/Step/WriteFile.zig2
-rw-r--r--lib/std/Io/Dir.zig10
-rw-r--r--lib/std/crypto/Certificate/Bundle.zig2
-rw-r--r--lib/std/crypto/codecs/asn1/test.zig2
-rw-r--r--lib/std/dynamic_library.zig6
-rw-r--r--lib/std/fs/test.zig54
-rw-r--r--lib/std/os/linux/IoUring.zig4
-rw-r--r--lib/std/zig/LibCInstallation.zig10
11 files changed, 52 insertions, 46 deletions
diff --git a/lib/std/Build.zig b/lib/std/Build.zig
index cc2f70fd2f..3d0e8b8dbc 100644
--- a/lib/std/Build.zig
+++ b/lib/std/Build.zig
@@ -2184,6 +2184,7 @@ fn dependencyInner(
pkg_deps: AvailableDeps,
args: anytype,
) *Dependency {
+ const io = b.graph.io;
const user_input_options = userInputOptionsFromArgs(b.allocator, args);
if (b.graph.dependency_cache.getContext(.{
.build_root_string = build_root_string,
@@ -2193,7 +2194,7 @@ fn dependencyInner(
const build_root: std.Build.Cache.Directory = .{
.path = build_root_string,
- .handle = Io.Dir.cwd().openDir(build_root_string, .{}) catch |err| {
+ .handle = Io.Dir.cwd().openDir(io, build_root_string, .{}) catch |err| {
std.debug.print("unable to open '{s}': {s}\n", .{
build_root_string, @errorName(err),
});
diff --git a/lib/std/Build/Cache/Path.zig b/lib/std/Build/Cache/Path.zig
index 60211670de..93e0c0d792 100644
--- a/lib/std/Build/Cache/Path.zig
+++ b/lib/std/Build/Cache/Path.zig
@@ -71,6 +71,7 @@ pub fn openFile(p: Path, io: Io, sub_path: []const u8, flags: Io.File.OpenFlags)
pub fn openDir(
p: Path,
+ io: Io,
sub_path: []const u8,
args: Io.Dir.OpenOptions,
) Io.Dir.OpenError!Io.Dir {
@@ -80,7 +81,7 @@ pub fn openDir(
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
- return p.root_dir.handle.openDir(joined_path, args);
+ return p.root_dir.handle.openDir(io, joined_path, args);
}
pub fn makeOpenPath(p: Path, sub_path: []const u8, opts: Io.Dir.OpenOptions) !Io.Dir {
diff --git a/lib/std/Build/Step/InstallArtifact.zig b/lib/std/Build/Step/InstallArtifact.zig
index 1cdb232770..4c1506aa33 100644
--- a/lib/std/Build/Step/InstallArtifact.zig
+++ b/lib/std/Build/Step/InstallArtifact.zig
@@ -164,7 +164,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
const src_dir_path = dir.source.getPath3(b, step);
const full_h_prefix = b.getInstallPath(h_dir, dir.dest_rel_path);
- var src_dir = src_dir_path.root_dir.handle.openDir(src_dir_path.subPathOrDot(), .{ .iterate = true }) catch |err| {
+ var src_dir = src_dir_path.root_dir.handle.openDir(io, src_dir_path.subPathOrDot(), .{ .iterate = true }) catch |err| {
return step.fail("unable to open source directory '{f}': {s}", .{
src_dir_path, @errorName(err),
});
diff --git a/lib/std/Build/Step/WriteFile.zig b/lib/std/Build/Step/WriteFile.zig
index 2834f18564..353c85fecf 100644
--- a/lib/std/Build/Step/WriteFile.zig
+++ b/lib/std/Build/Step/WriteFile.zig
@@ -218,7 +218,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
const need_derived_inputs = try step.addDirectoryWatchInput(dir.source);
const src_dir_path = dir.source.getPath3(b, step);
- var src_dir = src_dir_path.root_dir.handle.openDir(src_dir_path.subPathOrDot(), .{ .iterate = true }) catch |err| {
+ var src_dir = src_dir_path.root_dir.handle.openDir(io, src_dir_path.subPathOrDot(), .{ .iterate = true }) catch |err| {
return step.fail("unable to open source directory '{f}': {s}", .{
src_dir_path, @errorName(err),
});
diff --git a/lib/std/Io/Dir.zig b/lib/std/Io/Dir.zig
index 3b552a556a..9189a4c609 100644
--- a/lib/std/Io/Dir.zig
+++ b/lib/std/Io/Dir.zig
@@ -234,7 +234,7 @@ pub const SelectiveWalker = struct {
return;
}
- var new_dir = entry.dir.openDir(entry.basename, .{ .iterate = true }) catch |err| {
+ var new_dir = entry.dir.openDir(io, entry.basename, .{ .iterate = true }) catch |err| {
switch (err) {
error.NameTooLong => unreachable,
else => |e| return e,
@@ -1326,7 +1326,7 @@ pub fn deleteTree(dir: Dir, io: Io, sub_path: []const u8) DeleteTreeError!void {
var treat_as_dir = true;
handle_entry: while (true) {
if (treat_as_dir) {
- break :iterable_dir parent_dir.openDir(name, .{
+ break :iterable_dir parent_dir.openDir(io, name, .{
.follow_symlinks = false,
.iterate = true,
}) catch |err| switch (err) {
@@ -1430,7 +1430,7 @@ fn deleteTreeMinStackSizeWithKindHint(parent: Dir, io: Io, sub_path: []const u8,
var treat_as_dir = entry.kind == .directory;
handle_entry: while (true) {
if (treat_as_dir) {
- const new_dir = dir.openDir(entry.name, .{
+ const new_dir = dir.openDir(io, entry.name, .{
.follow_symlinks = false,
.iterate = true,
}) catch |err| switch (err) {
@@ -1520,14 +1520,14 @@ fn deleteTreeMinStackSizeWithKindHint(parent: Dir, io: Io, sub_path: []const u8,
}
/// On successful delete, returns null.
-fn deleteTreeOpenInitialSubpath(dir: Dir, sub_path: []const u8, kind_hint: File.Kind) !?Dir {
+fn deleteTreeOpenInitialSubpath(dir: Dir, io: Io, sub_path: []const u8, kind_hint: File.Kind) !?Dir {
return iterable_dir: {
// Treat as a file by default
var treat_as_dir = kind_hint == .directory;
handle_entry: while (true) {
if (treat_as_dir) {
- break :iterable_dir dir.openDir(sub_path, .{
+ break :iterable_dir dir.openDir(io, sub_path, .{
.follow_symlinks = false,
.iterate = true,
}) catch |err| switch (err) {
diff --git a/lib/std/crypto/Certificate/Bundle.zig b/lib/std/crypto/Certificate/Bundle.zig
index d4a9f1e757..1b87c97949 100644
--- a/lib/std/crypto/Certificate/Bundle.zig
+++ b/lib/std/crypto/Certificate/Bundle.zig
@@ -180,7 +180,7 @@ pub fn addCertsFromDirPath(
dir: Io.Dir,
sub_dir_path: []const u8,
) AddCertsFromDirPathError!void {
- var iterable_dir = try dir.openDir(sub_dir_path, .{ .iterate = true });
+ var iterable_dir = try dir.openDir(io, sub_dir_path, .{ .iterate = true });
defer iterable_dir.close(io);
return addCertsFromDir(cb, gpa, io, iterable_dir);
}
diff --git a/lib/std/crypto/codecs/asn1/test.zig b/lib/std/crypto/codecs/asn1/test.zig
index 3dbedb9f80..bdfb47e2df 100644
--- a/lib/std/crypto/codecs/asn1/test.zig
+++ b/lib/std/crypto/codecs/asn1/test.zig
@@ -73,7 +73,7 @@ test AllTypes {
try std.testing.expectEqualSlices(u8, encoded, buf);
// Use this to update test file.
- // const dir = try Io.Dir.cwd().openDir("lib/std/crypto/asn1", .{});
+ // const dir = try Io.Dir.cwd().openDir(io, "lib/std/crypto/asn1", .{});
// var file = try dir.createFile(io, path, .{});
// defer file.close(io);
// try file.writeAll(buf);
diff --git a/lib/std/dynamic_library.zig b/lib/std/dynamic_library.zig
index a1801d00d0..b1965b60ee 100644
--- a/lib/std/dynamic_library.zig
+++ b/lib/std/dynamic_library.zig
@@ -160,9 +160,9 @@ pub const ElfDynLib = struct {
fn openPath(path: []const u8, io: Io) !Io.Dir {
if (path.len == 0) return error.NotDir;
var parts = std.mem.tokenizeScalar(u8, path, '/');
- var parent = if (path[0] == '/') try Io.Dir.cwd().openDir("/", .{}) else Io.Dir.cwd();
+ var parent = if (path[0] == '/') try Io.Dir.cwd().openDir(io, "/", .{}) else Io.Dir.cwd();
while (parts.next()) |part| {
- const child = try parent.openDir(part, .{});
+ const child = try parent.openDir(io, part, .{});
parent.close(io);
parent = child;
}
@@ -184,7 +184,7 @@ pub const ElfDynLib = struct {
}
fn resolveFromParent(io: Io, dir_path: []const u8, file_name: []const u8) ?posix.fd_t {
- var dir = Io.Dir.cwd().openDir(dir_path, .{}) catch return null;
+ var dir = Io.Dir.cwd().openDir(io, dir_path, .{}) catch return null;
defer dir.close(io);
return posix.openat(dir.handle, file_name, .{
.ACCMODE = .RDONLY,
diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig
index aab86d40a6..9924cafaf8 100644
--- a/lib/std/fs/test.zig
+++ b/lib/std/fs/test.zig
@@ -367,7 +367,7 @@ test "openDir" {
for ([_][]const u8{ "", ".", ".." }) |sub_path| {
const dir_path = try fs.path.join(allocator, &.{ subdir_path, sub_path });
- var dir = try ctx.dir.openDir(dir_path, .{});
+ var dir = try ctx.dir.openDir(io, dir_path, .{});
defer dir.close(io);
}
}
@@ -448,7 +448,7 @@ test "openDirAbsolute" {
test "openDir cwd parent '..'" {
const io = testing.io;
- var dir = Io.Dir.cwd().openDir("..", .{}) catch |err| {
+ var dir = Io.Dir.cwd().openDir(io, "..", .{}) catch |err| {
if (native_os == .wasi and err == error.PermissionDenied) {
return; // This is okay. WASI disallows escaping from the fs sandbox
}
@@ -471,7 +471,7 @@ test "openDir non-cwd parent '..'" {
var subdir = try tmp.dir.makeOpenPath("subdir", .{});
defer subdir.close(io);
- var dir = try subdir.openDir("..", .{});
+ var dir = try subdir.openDir(io, "..", .{});
defer dir.close(io);
const expected_path = try tmp.dir.realpathAlloc(testing.allocator, ".");
@@ -839,7 +839,7 @@ test "directory operations on files" {
file.close(io);
try testing.expectError(error.PathAlreadyExists, ctx.dir.makeDir(test_file_name));
- try testing.expectError(error.NotDir, ctx.dir.openDir(test_file_name, .{}));
+ try testing.expectError(error.NotDir, ctx.dir.openDir(io, test_file_name, .{}));
try testing.expectError(error.NotDir, ctx.dir.deleteDir(test_file_name));
if (ctx.path_type == .absolute and comptime PathType.absolute.isSupported(builtin.os)) {
@@ -902,7 +902,7 @@ test "file operations on directories" {
}
// ensure the directory still exists as a sanity check
- var dir = try ctx.dir.openDir(test_dir_name, .{});
+ var dir = try ctx.dir.openDir(io, test_dir_name, .{});
dir.close(io);
}
}.impl);
@@ -918,7 +918,7 @@ test "makeOpenPath parent dirs do not exist" {
dir.close(io);
// double check that the full directory structure was created
- var dir_verification = try tmp_dir.dir.openDir("root_dir/parent_dir/some_dir", .{});
+ var dir_verification = try tmp_dir.dir.openDir(io, "root_dir/parent_dir/some_dir", .{});
dir_verification.close(io);
}
@@ -1005,8 +1005,8 @@ test "Dir.rename directories" {
try ctx.dir.rename(test_dir_path, test_dir_renamed_path);
// Ensure the directory was renamed
- try testing.expectError(error.FileNotFound, ctx.dir.openDir(test_dir_path, .{}));
- var dir = try ctx.dir.openDir(test_dir_renamed_path, .{});
+ try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_path, .{}));
+ var dir = try ctx.dir.openDir(io, test_dir_renamed_path, .{});
// Put a file in the directory
var file = try dir.createFile(io, "test_file", .{ .read = true });
@@ -1017,8 +1017,8 @@ test "Dir.rename directories" {
try ctx.dir.rename(test_dir_renamed_path, test_dir_renamed_again_path);
// Ensure the directory was renamed and the file still exists in it
- try testing.expectError(error.FileNotFound, ctx.dir.openDir(test_dir_renamed_path, .{}));
- dir = try ctx.dir.openDir(test_dir_renamed_again_path, .{});
+ try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_renamed_path, .{}));
+ dir = try ctx.dir.openDir(io, test_dir_renamed_again_path, .{});
file = try dir.openFile(io, "test_file", .{});
file.close(io);
dir.close(io);
@@ -1042,8 +1042,8 @@ test "Dir.rename directory onto empty dir" {
try ctx.dir.rename(test_dir_path, target_dir_path);
// Ensure the directory was renamed
- try testing.expectError(error.FileNotFound, ctx.dir.openDir(test_dir_path, .{}));
- var dir = try ctx.dir.openDir(target_dir_path, .{});
+ try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_path, .{}));
+ var dir = try ctx.dir.openDir(io, target_dir_path, .{});
dir.close(io);
}
}.impl);
@@ -1070,7 +1070,7 @@ test "Dir.rename directory onto non-empty dir" {
try testing.expectError(error.PathAlreadyExists, ctx.dir.rename(test_dir_path, target_dir_path));
// Ensure the directory was not renamed
- var dir = try ctx.dir.openDir(test_dir_path, .{});
+ var dir = try ctx.dir.openDir(io, test_dir_path, .{});
dir.close(io);
}
}.impl);
@@ -1165,8 +1165,8 @@ test "renameAbsolute" {
);
// ensure the directory was renamed
- try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir(test_dir_name, .{}));
- var dir = try tmp_dir.dir.openDir(renamed_test_dir_name, .{});
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir(io, test_dir_name, .{}));
+ var dir = try tmp_dir.dir.openDir(io, renamed_test_dir_name, .{});
dir.close(io);
}
@@ -1234,6 +1234,7 @@ test "deleteTree on a symlink" {
test "makePath, put some files in it, deleteTree" {
try testWithAllSupportedPathTypes(struct {
fn impl(ctx: *TestContext) !void {
+ const io = ctx.io;
const allocator = ctx.arena.allocator();
const dir_path = try ctx.transformPath("os_test_tmp");
@@ -1248,7 +1249,7 @@ test "makePath, put some files in it, deleteTree" {
});
try ctx.dir.deleteTree(dir_path);
- try testing.expectError(error.FileNotFound, ctx.dir.openDir(dir_path, .{}));
+ try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, dir_path, .{}));
}
}.impl);
}
@@ -1256,6 +1257,7 @@ test "makePath, put some files in it, deleteTree" {
test "makePath, put some files in it, deleteTreeMinStackSize" {
try testWithAllSupportedPathTypes(struct {
fn impl(ctx: *TestContext) !void {
+ const io = ctx.io;
const allocator = ctx.arena.allocator();
const dir_path = try ctx.transformPath("os_test_tmp");
@@ -1270,7 +1272,7 @@ test "makePath, put some files in it, deleteTreeMinStackSize" {
});
try ctx.dir.deleteTreeMinStackSize(dir_path);
- try testing.expectError(error.FileNotFound, ctx.dir.openDir(dir_path, .{}));
+ try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, dir_path, .{}));
}
}.impl);
}
@@ -1296,7 +1298,7 @@ test "makePath but sub_path contains pre-existing file" {
}
fn expectDir(io: Io, dir: Dir, path: []const u8) !void {
- var d = try dir.openDir(path, .{});
+ var d = try dir.openDir(io, path, .{});
d.close(io);
}
@@ -1307,7 +1309,7 @@ test "makepath existing directories" {
defer tmp.cleanup();
try tmp.dir.makeDir("A");
- var tmpA = try tmp.dir.openDir("A", .{});
+ var tmpA = try tmp.dir.openDir(io, "A", .{});
defer tmpA.close(io);
try tmpA.makeDir("B");
@@ -1569,7 +1571,7 @@ test "sendfile" {
try tmp.dir.makePath("os_test_tmp");
- var dir = try tmp.dir.openDir("os_test_tmp", .{});
+ var dir = try tmp.dir.openDir(io, "os_test_tmp", .{});
defer dir.close(io);
const line1 = "line1\n";
@@ -1616,7 +1618,7 @@ test "sendfile with buffered data" {
try tmp.dir.makePath("os_test_tmp");
- var dir = try tmp.dir.openDir("os_test_tmp", .{});
+ var dir = try tmp.dir.openDir(io, "os_test_tmp", .{});
defer dir.close(io);
var src_file = try dir.createFile(io, "sendfile1.txt", .{ .read = true });
@@ -1913,7 +1915,7 @@ test "walker" {
return err;
};
// make sure that the entry.dir is the containing dir
- var entry_dir = try entry.dir.openDir(entry.basename, .{});
+ var entry_dir = try entry.dir.openDir(io, entry.basename, .{});
defer entry_dir.close(io);
num_walked += 1;
}
@@ -1981,7 +1983,7 @@ test "selective walker, skip entries that start with ." {
};
// make sure that the entry.dir is the containing dir
- var entry_dir = try entry.dir.openDir(entry.basename, .{});
+ var entry_dir = try entry.dir.openDir(io, entry.basename, .{});
defer entry_dir.close(io);
num_walked += 1;
}
@@ -2026,7 +2028,7 @@ test "'.' and '..' in Io.Dir functions" {
try ctx.dir.makeDir(subdir_path);
try ctx.dir.access(subdir_path, .{});
- var created_subdir = try ctx.dir.openDir(subdir_path, .{});
+ var created_subdir = try ctx.dir.openDir(io, subdir_path, .{});
created_subdir.close(io);
const created_file = try ctx.dir.createFile(io, file_path, .{});
@@ -2103,7 +2105,7 @@ test "chmod" {
try testing.expectEqual(@as(File.Mode, 0o644), (try file.stat()).mode & 0o7777);
try tmp.dir.makeDir("test_dir");
- var dir = try tmp.dir.openDir("test_dir", .{ .iterate = true });
+ var dir = try tmp.dir.openDir(io, "test_dir", .{ .iterate = true });
defer dir.close(io);
try dir.chmod(0o700);
@@ -2125,7 +2127,7 @@ test "chown" {
try tmp.dir.makeDir("test_dir");
- var dir = try tmp.dir.openDir("test_dir", .{ .iterate = true });
+ var dir = try tmp.dir.openDir(io, "test_dir", .{ .iterate = true });
defer dir.close(io);
try dir.chown(null, null);
}
diff --git a/lib/std/os/linux/IoUring.zig b/lib/std/os/linux/IoUring.zig
index 0972a302da..167c6ef398 100644
--- a/lib/std/os/linux/IoUring.zig
+++ b/lib/std/os/linux/IoUring.zig
@@ -3066,6 +3066,8 @@ test "unlinkat" {
test "mkdirat" {
if (!is_linux) return error.SkipZigTest;
+ const io = testing.io;
+
var ring = IoUring.init(1, 0) catch |err| switch (err) {
error.SystemOutdated => return error.SkipZigTest,
error.PermissionDenied => return error.SkipZigTest,
@@ -3104,7 +3106,7 @@ test "mkdirat" {
}, cqe);
// Validate that the directory exist
- _ = try tmp.dir.openDir(path, .{});
+ _ = try tmp.dir.openDir(io, path, .{});
}
test "symlinkat" {
diff --git a/lib/std/zig/LibCInstallation.zig b/lib/std/zig/LibCInstallation.zig
index 80317850df..a5c55d3522 100644
--- a/lib/std/zig/LibCInstallation.zig
+++ b/lib/std/zig/LibCInstallation.zig
@@ -337,7 +337,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, args: FindNativeOptions) F
// search in reverse order
const search_path_untrimmed = search_paths.items[search_paths.items.len - path_i - 1];
const search_path = std.mem.trimStart(u8, search_path_untrimmed, " ");
- var search_dir = Io.Dir.cwd().openDir(search_path, .{}) catch |err| switch (err) {
+ var search_dir = Io.Dir.cwd().openDir(io, search_path, .{}) catch |err| switch (err) {
error.FileNotFound,
error.NotDir,
error.NoDevice,
@@ -392,7 +392,7 @@ fn findNativeIncludeDirWindows(
result_buf.shrinkAndFree(0);
try result_buf.print("{s}\\Include\\{s}\\ucrt", .{ install.path, install.version });
- var dir = Io.Dir.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {
+ var dir = Io.Dir.cwd().openDir(io, result_buf.items, .{}) catch |err| switch (err) {
error.FileNotFound,
error.NotDir,
error.NoDevice,
@@ -440,7 +440,7 @@ fn findNativeCrtDirWindows(
result_buf.shrinkAndFree(0);
try result_buf.print("{s}\\Lib\\{s}\\ucrt\\{s}", .{ install.path, install.version, arch_sub_dir });
- var dir = Io.Dir.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {
+ var dir = Io.Dir.cwd().openDir(io, result_buf.items, .{}) catch |err| switch (err) {
error.FileNotFound,
error.NotDir,
error.NoDevice,
@@ -508,7 +508,7 @@ fn findNativeKernel32LibDir(
result_buf.shrinkAndFree(0);
try result_buf.print("{s}\\Lib\\{s}\\um\\{s}", .{ install.path, install.version, arch_sub_dir });
- var dir = Io.Dir.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {
+ var dir = Io.Dir.cwd().openDir(io, result_buf.items, .{}) catch |err| switch (err) {
error.FileNotFound,
error.NotDir,
error.NoDevice,
@@ -544,7 +544,7 @@ fn findNativeMsvcIncludeDir(
const dir_path = try fs.path.join(allocator, &[_][]const u8{ up2, "include" });
errdefer allocator.free(dir_path);
- var dir = Io.Dir.cwd().openDir(dir_path, .{}) catch |err| switch (err) {
+ var dir = Io.Dir.cwd().openDir(io, dir_path, .{}) catch |err| switch (err) {
error.FileNotFound,
error.NotDir,
error.NoDevice,