authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-06 17:52:57-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:08-08:00
log8328de24f13e21e325207b19288a143854df50df
treeef7c9c46f969e31258a4c052c85f5a9ecfc34b80
parentdd1d15b72aa3bae4b38e2337609758ffb7a7b55a

update all occurrences of openFile to receive an io instance


41 files changed, 124 insertions(+), 138 deletions(-)

lib/compiler/aro/aro/Compilation.zig+2-2
......@@ -1641,7 +1641,7 @@ fn addSourceFromPathExtra(comp: *Compilation, path: []const u8, kind: Source.Kin
16411641
16421642 const io = comp.io;
16431643
1644 const file = try comp.cwd.openFile(path, .{});
1644 const file = try comp.cwd.openFile(io, path, .{});
16451645 defer file.close(io);
16461646 return comp.addSourceFromFile(file, path, kind);
16471647}
......@@ -1975,7 +1975,7 @@ fn getPathContents(comp: *Compilation, path: []const u8, limit: Io.Limit) ![]u8
19751975
19761976 const io = comp.io;
19771977
1978 const file = try comp.cwd.openFile(path, .{});
1978 const file = try comp.cwd.openFile(io, path, .{});
19791979 defer file.close(io);
19801980 return comp.getFileContents(file, limit);
19811981}
lib/compiler/aro/aro/Driver/Filesystem.zig+1-1
......@@ -213,7 +213,7 @@ pub const Filesystem = union(enum) {
213213 pub fn readFile(fs: Filesystem, io: Io, path: []const u8, buf: []u8) ?[]const u8 {
214214 return switch (fs) {
215215 .real => |cwd| {
216 const file = cwd.openFile(path, .{}) catch return null;
216 const file = cwd.openFile(io, path, .{}) catch return null;
217217 defer file.close(io);
218218
219219 const bytes_read = file.readAll(buf) catch return null;
lib/compiler/aro/aro/Toolchain.zig+3-3
......@@ -524,12 +524,12 @@ pub fn addBuiltinIncludeDir(tc: *const Toolchain) !void {
524524/// Otherwise returns a slice of `buf`. If the file is larger than `buf` partial contents are returned
525525pub fn readFile(tc: *const Toolchain, path: []const u8, buf: []u8) ?[]const u8 {
526526 const comp = tc.driver.comp;
527 return comp.cwd.adaptToNewApi().readFile(comp.io, path, buf) catch null;
527 return comp.cwd.readFile(comp.io, path, buf) catch null;
528528}
529529
530530pub fn exists(tc: *const Toolchain, path: []const u8) bool {
531531 const comp = tc.driver.comp;
532 comp.cwd.adaptToNewApi().access(comp.io, path, .{}) catch return false;
532 comp.cwd.access(comp.io, path, .{}) catch return false;
533533 return true;
534534}
535535
......@@ -547,7 +547,7 @@ pub fn canExecute(tc: *const Toolchain, path: []const u8) bool {
547547 }
548548
549549 const comp = tc.driver.comp;
550 comp.cwd.adaptToNewApi().access(comp.io, path, .{ .execute = true }) catch return false;
550 comp.cwd.access(comp.io, path, .{ .execute = true }) catch return false;
551551 // Todo: ensure path is not a directory
552552 return true;
553553}
lib/compiler/objcopy.zig+1-1
......@@ -157,7 +157,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
157157
158158 const stat = input_file.stat() catch |err| fatal("failed to stat {s}: {t}", .{ input, err });
159159
160 var in: File.Reader = .initSize(input_file.adaptToNewApi(), io, &input_buffer, stat.size);
160 var in: File.Reader = .initSize(input_file, io, &input_buffer, stat.size);
161161
162162 const elf_hdr = std.elf.Header.read(&in.interface) catch |err| switch (err) {
163163 error.ReadFailed => fatal("unable to read {s}: {t}", .{ input, in.err.? }),
lib/compiler/std-docs.zig+1-1
......@@ -225,7 +225,7 @@ fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void {
225225 },
226226 else => continue,
227227 }
228 var file = try entry.dir.openFile(entry.basename, .{});
228 var file = try entry.dir.openFile(io, entry.basename, .{});
229229 defer file.close(io);
230230 const stat = try file.stat();
231231 var file_reader: std.Io.File.Reader = .{
lib/std/Build/Cache.zig+5-3
......@@ -502,6 +502,8 @@ pub const Manifest = struct {
502502 @memcpy(manifest_file_path[0..self.hex_digest.len], &self.hex_digest);
503503 manifest_file_path[hex_digest_len..][0..ext.len].* = ext.*;
504504
505 const io = self.cache.io;
506
505507 // We'll try to open the cache with an exclusive lock, but if that would block
506508 // and `want_shared_lock` is set, a shared lock might be sufficient, so we'll
507509 // open with a shared lock instead.
......@@ -517,7 +519,7 @@ pub const Manifest = struct {
517519 break;
518520 } else |err| switch (err) {
519521 error.WouldBlock => {
520 self.manifest_file = self.cache.manifest_dir.openFile(&manifest_file_path, .{
522 self.manifest_file = self.cache.manifest_dir.openFile(io, &manifest_file_path, .{
521523 .mode = .read_write,
522524 .lock = .shared,
523525 }) catch |e| {
......@@ -757,7 +759,7 @@ pub const Manifest = struct {
757759
758760 const pp = cache_hash_file.prefixed_path;
759761 const dir = self.cache.prefixes()[pp.prefix].handle;
760 const this_file = dir.openFile(pp.sub_path, .{ .mode = .read_only }) catch |err| switch (err) {
762 const this_file = dir.openFile(io, pp.sub_path, .{ .mode = .read_only }) catch |err| switch (err) {
761763 error.FileNotFound => {
762764 // Every digest before this one has been populated successfully.
763765 return .{ .miss = .{ .file_digests_populated = idx } };
......@@ -900,7 +902,7 @@ pub const Manifest = struct {
900902 } else {
901903 const pp = ch_file.prefixed_path;
902904 const dir = self.cache.prefixes()[pp.prefix].handle;
903 const handle = try dir.openFile(pp.sub_path, .{});
905 const handle = try dir.openFile(io, pp.sub_path, .{});
904906 defer handle.close(io);
905907 return populateFileHashHandle(self, ch_file, handle);
906908 }
lib/std/Build/Cache/Path.zig+2-6
......@@ -59,18 +59,14 @@ pub fn joinStringZ(p: Path, gpa: Allocator, sub_path: []const u8) Allocator.Erro
5959 return p.root_dir.joinZ(gpa, parts);
6060}
6161
62pub fn openFile(
63 p: Path,
64 sub_path: []const u8,
65 flags: Io.File.OpenFlags,
66) !Io.File {
62pub fn openFile(p: Path, io: Io, sub_path: []const u8, flags: Io.File.OpenFlags) !Io.File {
6763 var buf: [fs.max_path_bytes]u8 = undefined;
6864 const joined_path = if (p.sub_path.len == 0) sub_path else p: {
6965 break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
7066 p.sub_path, sub_path,
7167 }) catch return error.NameTooLong;
7268 };
73 return p.root_dir.handle.openFile(joined_path, flags);
69 return p.root_dir.handle.openFile(io, joined_path, flags);
7470}
7571
7672pub fn openDir(
lib/std/Build/Fuzz.zig+2-2
......@@ -405,7 +405,7 @@ fn prepareTables(fuzz: *Fuzz, run_step: *Step.Run, coverage_id: u64) error{ OutO
405405 .root_dir = run_step.step.owner.cache_root,
406406 .sub_path = "v/" ++ std.fmt.hex(coverage_id),
407407 };
408 var coverage_file = coverage_file_path.root_dir.handle.openFile(coverage_file_path.sub_path, .{}) catch |err| {
408 var coverage_file = coverage_file_path.root_dir.handle.openFile(io, coverage_file_path.sub_path, .{}) catch |err| {
409409 log.err("step '{s}': failed to load coverage file '{f}': {t}", .{
410410 run_step.step.name, coverage_file_path, err,
411411 });
......@@ -528,7 +528,7 @@ pub fn waitAndPrintReport(fuzz: *Fuzz) void {
528528 .root_dir = cov.run.step.owner.cache_root,
529529 .sub_path = "v/" ++ std.fmt.hex(cov.id),
530530 };
531 var coverage_file = coverage_file_path.root_dir.handle.openFile(coverage_file_path.sub_path, .{}) catch |err| {
531 var coverage_file = coverage_file_path.root_dir.handle.openFile(io, coverage_file_path.sub_path, .{}) catch |err| {
532532 fatal("step '{s}': failed to load coverage file '{f}': {t}", .{
533533 cov.run.step.name, coverage_file_path, err,
534534 });
lib/std/Build/Step/Run.zig+3-3
......@@ -846,7 +846,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
846846 errdefer result.deinit();
847847 result.writer.writeAll(file_plp.prefix) catch return error.OutOfMemory;
848848
849 const file = file_path.root_dir.handle.openFile(file_path.subPathOrDot(), .{}) catch |err| {
849 const file = file_path.root_dir.handle.openFile(io, file_path.subPathOrDot(), .{}) catch |err| {
850850 return step.fail(
851851 "unable to open input file '{f}': {t}",
852852 .{ file_path, err },
......@@ -1111,7 +1111,7 @@ pub fn rerunInFuzzMode(
11111111 errdefer result.deinit();
11121112 result.writer.writeAll(file_plp.prefix) catch return error.OutOfMemory;
11131113
1114 const file = try file_path.root_dir.handle.openFile(file_path.subPathOrDot(), .{});
1114 const file = try file_path.root_dir.handle.openFile(io, file_path.subPathOrDot(), .{});
11151115 defer file.close(io);
11161116
11171117 var buf: [1024]u8 = undefined;
......@@ -2185,7 +2185,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult {
21852185 },
21862186 .lazy_path => |lazy_path| {
21872187 const path = lazy_path.getPath3(b, &run.step);
2188 const file = path.root_dir.handle.openFile(path.subPathOrDot(), .{}) catch |err| {
2188 const file = path.root_dir.handle.openFile(io, path.subPathOrDot(), .{}) catch |err| {
21892189 return run.step.fail("unable to open stdin file: {s}", .{@errorName(err)});
21902190 };
21912191 defer file.close(io);
lib/std/Build/Step/UpdateSourceFiles.zig+1-1
......@@ -99,7 +99,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
9999 .cwd(),
100100 io,
101101 source_path,
102 b.build_root.handle.adaptToNewApi(),
102 b.build_root.handle,
103103 output_source_file.sub_path,
104104 .{},
105105 ) catch |err| {
lib/std/Build/Step/WriteFile.zig+3-3
......@@ -284,7 +284,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
284284 },
285285 .copy => |file_source| {
286286 const source_path = file_source.getPath2(b, step);
287 const prev_status = Io.Dir.updateFile(.cwd(), io, source_path, cache_dir.adaptToNewApi(), file.sub_path, .{}) catch |err| {
287 const prev_status = Io.Dir.updateFile(.cwd(), io, source_path, cache_dir, file.sub_path, .{}) catch |err| {
288288 return step.fail("unable to update file from '{s}' to '{f}{s}{c}{s}': {t}", .{
289289 source_path, b.cache_root, cache_path, fs.path.sep, file.sub_path, err,
290290 });
......@@ -321,10 +321,10 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
321321 .directory => try cache_dir.makePath(dest_path),
322322 .file => {
323323 const prev_status = Io.Dir.updateFile(
324 src_entry_path.root_dir.handle.adaptToNewApi(),
324 src_entry_path.root_dir.handle,
325325 io,
326326 src_entry_path.sub_path,
327 cache_dir.adaptToNewApi(),
327 cache_dir,
328328 dest_path,
329329 .{},
330330 ) catch |err| {
lib/std/Build/WebServer.zig+2-2
......@@ -504,14 +504,14 @@ pub fn serveTarFile(ws: *WebServer, request: *http.Server.Request, paths: []cons
504504 var archiver: std.tar.Writer = .{ .underlying_writer = &response.writer };
505505
506506 for (paths) |path| {
507 var file = path.root_dir.handle.openFile(path.sub_path, .{}) catch |err| {
507 var file = path.root_dir.handle.openFile(io, path.sub_path, .{}) catch |err| {
508508 log.err("failed to open '{f}': {s}", .{ path, @errorName(err) });
509509 continue;
510510 };
511511 defer file.close(io);
512512 const stat = try file.stat();
513513 var read_buffer: [1024]u8 = undefined;
514 var file_reader: Io.File.Reader = .initSize(file.adaptToNewApi(), io, &read_buffer, stat.size);
514 var file_reader: Io.File.Reader = .initSize(file, io, &read_buffer, stat.size);
515515
516516 // TODO: this logic is completely bogus -- obviously so, because `path.root_dir.path` can
517517 // be cwd-relative. This is also related to why linkification doesn't work in the fuzzer UI:
lib/std/Io/Dir.zig+1-1
......@@ -481,7 +481,7 @@ pub fn updateFile(
481481 }
482482
483483 var buffer: [1000]u8 = undefined; // Used only when direct fd-to-fd is not available.
484 var atomic_file = try Dir.atomicFile(.adaptFromNewApi(dest_dir), dest_path, .{
484 var atomic_file = try Dir.atomicFile(dest_dir, dest_path, .{
485485 .permissions = actual_permissions,
486486 .write_buffer = &buffer,
487487 });
lib/std/Io/test.zig+1-1
......@@ -44,7 +44,7 @@ test "write a file, read it, then delete it" {
4444 }
4545
4646 {
47 var file = try tmp.dir.openFile(tmp_file_name, .{});
47 var file = try tmp.dir.openFile(io, tmp_file_name, .{});
4848 defer file.close(io);
4949
5050 const file_size = try file.getEndPos();
lib/std/Thread.zig+2-2
......@@ -208,7 +208,7 @@ pub fn setName(self: Thread, io: Io, name: []const u8) SetNameError!void {
208208 var buf: [32]u8 = undefined;
209209 const path = try std.fmt.bufPrint(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()});
210210
211 const file = try std.fs.cwd().openFile(path, .{ .mode = .write_only });
211 const file = try std.fs.cwd().openFile(io, path, .{ .mode = .write_only });
212212 defer file.close(io);
213213
214214 try file.writeAll(name);
......@@ -325,7 +325,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
325325 var threaded: std.Io.Threaded = .init_single_threaded;
326326 const io = threaded.ioBasic();
327327
328 const file = try std.fs.cwd().openFile(path, .{});
328 const file = try std.fs.cwd().openFile(io, path, .{});
329329 defer file.close(io);
330330
331331 var file_reader = file.readerStreaming(io, &.{});
lib/std/crypto/Certificate/Bundle.zig+1-1
......@@ -208,7 +208,7 @@ pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp, i
208208 else => continue,
209209 }
210210
211 try addCertsFromFilePath(cb, gpa, io, now, iterable_dir.adaptToNewApi(), entry.name);
211 try addCertsFromFilePath(cb, gpa, io, now, iterable_dir, entry.name);
212212 }
213213}
214214
lib/std/debug/ElfFile.zig+1-1
......@@ -375,7 +375,7 @@ fn loadSeparateDebugFile(
375375 args: anytype,
376376) Allocator.Error!?[]align(std.heap.page_size_min) const u8 {
377377 const path = try std.fmt.allocPrint(arena, fmt, args);
378 const elf_file = std.fs.cwd().openFile(path, .{}) catch return null;
378 const elf_file = std.fs.cwd().openFile(io, path, .{}) catch return null;
379379 defer elf_file.close(io);
380380
381381 const result = loadInner(arena, elf_file, opt_crc) catch |err| switch (err) {
lib/std/debug/Info.zig+1-1
......@@ -39,7 +39,7 @@ pub fn load(
3939) LoadError!Info {
4040 switch (format) {
4141 .elf => {
42 var file = try path.root_dir.handle.openFile(path.sub_path, .{});
42 var file = try path.root_dir.handle.openFile(io, path.sub_path, .{});
4343 defer file.close(io);
4444
4545 var elf_file: ElfFile = try .load(gpa, file, null, &.none);
lib/std/debug/MachOFile.zig+1-1
......@@ -512,7 +512,7 @@ fn loadOFile(gpa: Allocator, io: Io, o_file_name: []const u8) !OFile {
512512
513513/// Uses `mmap` to map the file at `path` into memory.
514514fn mapDebugInfoFile(io: Io, path: []const u8) ![]align(std.heap.page_size_min) const u8 {
515 const file = std.fs.cwd().openFile(path, .{}) catch |err| switch (err) {
515 const file = std.fs.cwd().openFile(io, path, .{}) catch |err| switch (err) {
516516 error.FileNotFound => return error.MissingDebugInfo,
517517 else => return error.ReadFailed,
518518 };
lib/std/debug/SelfInfo/Elf.zig+2-2
......@@ -325,7 +325,7 @@ const Module = struct {
325325 }
326326 fn loadElf(mod: *Module, gpa: Allocator, io: Io) Error!LoadedElf {
327327 const load_result = if (mod.name.len > 0) res: {
328 var file = std.fs.cwd().openFile(mod.name, .{}) catch return error.MissingDebugInfo;
328 var file = std.fs.cwd().openFile(io, mod.name, .{}) catch return error.MissingDebugInfo;
329329 defer file.close(io);
330330 break :res std.debug.ElfFile.load(gpa, file, mod.build_id, &.native(mod.name));
331331 } else res: {
......@@ -334,7 +334,7 @@ const Module = struct {
334334 else => return error.ReadFailed,
335335 };
336336 defer gpa.free(path);
337 var file = std.fs.cwd().openFile(path, .{}) catch return error.MissingDebugInfo;
337 var file = std.fs.cwd().openFile(io, path, .{}) catch return error.MissingDebugInfo;
338338 defer file.close(io);
339339 break :res std.debug.ElfFile.load(gpa, file, mod.build_id, &.native(path));
340340 };
lib/std/debug/SelfInfo/MachO.zig+1-1
......@@ -616,7 +616,7 @@ test {
616616
617617/// Uses `mmap` to map the file at `path` into memory.
618618fn mapDebugInfoFile(io: Io, path: []const u8) ![]align(std.heap.page_size_min) const u8 {
619 const file = std.fs.cwd().openFile(path, .{}) catch |err| switch (err) {
619 const file = std.fs.cwd().openFile(io, path, .{}) catch |err| switch (err) {
620620 error.FileNotFound => return error.MissingDebugInfo,
621621 else => return error.ReadFailed,
622622 };
lib/std/debug/SelfInfo/Windows.zig+3-3
......@@ -387,7 +387,7 @@ const Module = struct {
387387 const section_view = section_view_ptr.?[0..coff_len];
388388 coff_obj = coff.Coff.init(section_view, false) catch return error.InvalidDebugInfo;
389389 break :mapped .{
390 .file = .adaptFromNewApi(coff_file),
390 .file = coff_file,
391391 .section_handle = section_handle,
392392 .section_view = section_view,
393393 };
......@@ -432,7 +432,7 @@ const Module = struct {
432432 break :pdb null;
433433 };
434434 const pdb_file_open_result = if (fs.path.isAbsolute(path)) res: {
435 break :res std.fs.cwd().openFile(path, .{});
435 break :res std.fs.cwd().openFile(io, path, .{});
436436 } else res: {
437437 const self_dir = fs.selfExeDirPathAlloc(gpa) catch |err| switch (err) {
438438 error.OutOfMemory, error.Unexpected => |e| return e,
......@@ -441,7 +441,7 @@ const Module = struct {
441441 defer gpa.free(self_dir);
442442 const abs_path = try fs.path.join(gpa, &.{ self_dir, path });
443443 defer gpa.free(abs_path);
444 break :res std.fs.cwd().openFile(abs_path, .{});
444 break :res std.fs.cwd().openFile(io, abs_path, .{});
445445 };
446446 const pdb_file = pdb_file_open_result catch |err| switch (err) {
447447 error.FileNotFound, error.IsDir => break :pdb null,
lib/std/fs.zig-17
......@@ -287,23 +287,6 @@ pub fn symLinkAbsoluteW(
287287 return windows.CreateSymbolicLink(null, mem.span(sym_link_path_w), mem.span(target_path_w), flags.is_directory);
288288}
289289
290pub const OpenSelfExeError = Io.File.OpenSelfExeError;
291
292/// Deprecated in favor of `Io.File.openSelfExe`.
293pub fn openSelfExe(flags: File.OpenFlags) OpenSelfExeError!File {
294 if (native_os == .linux or native_os == .serenity or native_os == .windows) {
295 var threaded: Io.Threaded = .init_single_threaded;
296 const io = threaded.ioBasic();
297 return .adaptFromNewApi(try Io.File.openSelfExe(io, flags));
298 }
299 // Use of max_path_bytes here is valid as the resulting path is immediately
300 // opened with no modification.
301 var buf: [max_path_bytes]u8 = undefined;
302 const self_exe_path = try selfExePath(&buf);
303 buf[self_exe_path.len] = 0;
304 return openFileAbsolute(buf[0..self_exe_path.len :0], flags);
305}
306
307290// This is `posix.ReadLinkError || posix.RealPathError` with impossible errors excluded
308291pub const SelfExePathError = error{
309292 FileNotFound,
lib/std/fs/test.zig+23-23
......@@ -855,7 +855,7 @@ test "directory operations on files" {
855855 }
856856
857857 // ensure the file still exists and is a file as a sanity check
858 file = try ctx.dir.openFile(test_file_name, .{});
858 file = try ctx.dir.openFile(io, test_file_name, .{});
859859 const stat = try file.stat();
860860 try testing.expectEqual(File.Kind.file, stat.kind);
861861 file.close(io);
......@@ -895,12 +895,12 @@ test "file operations on directories" {
895895
896896 if (native_os == .wasi and builtin.link_libc) {
897897 // wasmtime unexpectedly succeeds here, see https://github.com/ziglang/zig/issues/20747
898 const handle = try ctx.dir.openFile(test_dir_name, .{ .mode = .read_write });
898 const handle = try ctx.dir.openFile(io, test_dir_name, .{ .mode = .read_write });
899899 handle.close(io);
900900 } else {
901901 // Note: The `.mode = .read_write` is necessary to ensure the error occurs on all platforms.
902902 // TODO: Add a read-only test as well, see https://github.com/ziglang/zig/issues/5732
903 try testing.expectError(error.IsDir, ctx.dir.openFile(test_dir_name, .{ .mode = .read_write }));
903 try testing.expectError(error.IsDir, ctx.dir.openFile(io, test_dir_name, .{ .mode = .read_write }));
904904 }
905905
906906 if (ctx.path_type == .absolute and comptime PathType.absolute.isSupported(builtin.os)) {
......@@ -973,8 +973,8 @@ test "Dir.rename files" {
973973 try ctx.dir.rename(test_file_name, renamed_test_file_name);
974974
975975 // Ensure the file was renamed
976 try testing.expectError(error.FileNotFound, ctx.dir.openFile(test_file_name, .{}));
977 file = try ctx.dir.openFile(renamed_test_file_name, .{});
976 try testing.expectError(error.FileNotFound, ctx.dir.openFile(io, test_file_name, .{}));
977 file = try ctx.dir.openFile(io, renamed_test_file_name, .{});
978978 file.close(io);
979979
980980 // Rename to self succeeds
......@@ -986,8 +986,8 @@ test "Dir.rename files" {
986986 existing_file.close(io);
987987 try ctx.dir.rename(renamed_test_file_name, existing_file_path);
988988
989 try testing.expectError(error.FileNotFound, ctx.dir.openFile(renamed_test_file_name, .{}));
990 file = try ctx.dir.openFile(existing_file_path, .{});
989 try testing.expectError(error.FileNotFound, ctx.dir.openFile(io, renamed_test_file_name, .{}));
990 file = try ctx.dir.openFile(io, existing_file_path, .{});
991991 file.close(io);
992992 }
993993 }.impl);
......@@ -1026,7 +1026,7 @@ test "Dir.rename directories" {
10261026 // Ensure the directory was renamed and the file still exists in it
10271027 try testing.expectError(error.FileNotFound, ctx.dir.openDir(test_dir_renamed_path, .{}));
10281028 dir = try ctx.dir.openDir(test_dir_renamed_again_path, .{});
1029 file = try dir.openFile("test_file", .{});
1029 file = try dir.openFile(io, "test_file", .{});
10301030 file.close(io);
10311031 dir.close(io);
10321032 }
......@@ -1119,8 +1119,8 @@ test "rename" {
11191119 try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name);
11201120
11211121 // ensure the file was renamed
1122 try testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(test_file_name, .{}));
1123 file = try tmp_dir2.dir.openFile(renamed_test_file_name, .{});
1122 try testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(io, test_file_name, .{}));
1123 file = try tmp_dir2.dir.openFile(io, renamed_test_file_name, .{});
11241124 file.close(io);
11251125}
11261126
......@@ -1156,8 +1156,8 @@ test "renameAbsolute" {
11561156 );
11571157
11581158 // ensure the file was renamed
1159 try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
1160 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
1159 try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(io, test_file_name, .{}));
1160 file = try tmp_dir.dir.openFile(io, renamed_test_file_name, .{});
11611161 const stat = try file.stat();
11621162 try testing.expectEqual(File.Kind.file, stat.kind);
11631163 file.close(io);
......@@ -1512,7 +1512,7 @@ test "setEndPos" {
15121512
15131513 const file_name = "afile.txt";
15141514 try tmp.dir.writeFile(.{ .sub_path = file_name, .data = "ninebytes" });
1515 const f = try tmp.dir.openFile(file_name, .{ .mode = .read_write });
1515 const f = try tmp.dir.openFile(io, file_name, .{ .mode = .read_write });
15161516 defer f.close(io);
15171517
15181518 const initial_size = try f.getEndPos();
......@@ -1856,7 +1856,7 @@ test "read from locked file" {
18561856 .lock = .exclusive,
18571857 });
18581858 defer f.close(io);
1859 const f2 = try ctx.dir.openFile(filename, .{});
1859 const f2 = try ctx.dir.openFile(io, filename, .{});
18601860 defer f2.close(io);
18611861 var buffer: [1]u8 = undefined;
18621862 if (builtin.os.tag == .windows) {
......@@ -2041,12 +2041,12 @@ test "'.' and '..' in Io.Dir functions" {
20412041
20422042 try ctx.dir.copyFile(file_path, ctx.dir, copy_path, .{});
20432043 try ctx.dir.rename(copy_path, rename_path);
2044 const renamed_file = try ctx.dir.openFile(rename_path, .{});
2044 const renamed_file = try ctx.dir.openFile(io, rename_path, .{});
20452045 renamed_file.close(io);
20462046 try ctx.dir.deleteFile(rename_path);
20472047
20482048 try ctx.dir.writeFile(.{ .sub_path = update_path, .data = "something" });
2049 var dir = ctx.dir.adaptToNewApi();
2049 var dir = ctx.dir;
20502050 const prev_status = try dir.updateFile(io, file_path, dir, update_path, .{});
20512051 try testing.expectEqual(Io.Dir.PrevStatus.stale, prev_status);
20522052
......@@ -2186,7 +2186,7 @@ test "invalid UTF-8/WTF-8 paths" {
21862186
21872187 try testing.expectError(expected_err, ctx.dir.access(invalid_path, .{}));
21882188
2189 var dir = ctx.dir.adaptToNewApi();
2189 var dir = ctx.dir;
21902190 try testing.expectError(expected_err, dir.updateFile(io, invalid_path, dir, invalid_path, .{}));
21912191 try testing.expectError(expected_err, ctx.dir.copyFile(invalid_path, ctx.dir, invalid_path, .{}));
21922192
......@@ -2235,7 +2235,7 @@ test "read file non vectored" {
22352235 try file_writer.interface.flush();
22362236 }
22372237
2238 var file_reader: std.Io.File.Reader = .initAdapted(file, io, &.{});
2238 var file_reader: std.Io.File.Reader = .init(file, io, &.{});
22392239
22402240 var write_buffer: [100]u8 = undefined;
22412241 var w: std.Io.Writer = .fixed(&write_buffer);
......@@ -2268,7 +2268,7 @@ test "seek keeping partial buffer" {
22682268 }
22692269
22702270 var read_buffer: [3]u8 = undefined;
2271 var file_reader: Io.File.Reader = .initAdapted(file, io, &read_buffer);
2271 var file_reader: Io.File.Reader = .init(file, io, &read_buffer);
22722272
22732273 try testing.expectEqual(0, file_reader.logicalPos());
22742274
......@@ -2301,7 +2301,7 @@ test "seekBy" {
23012301 defer tmp_dir.cleanup();
23022302
23032303 try tmp_dir.dir.writeFile(.{ .sub_path = "blah.txt", .data = "let's test seekBy" });
2304 const f = try tmp_dir.dir.openFile("blah.txt", .{ .mode = .read_only });
2304 const f = try tmp_dir.dir.openFile(io, "blah.txt", .{ .mode = .read_only });
23052305 defer f.close(io);
23062306 var reader = f.readerStreaming(io, &.{});
23072307 try reader.seekBy(2);
......@@ -2332,7 +2332,7 @@ test "seekTo flushes buffered data" {
23322332 }
23332333
23342334 var read_buffer: [16]u8 = undefined;
2335 var file_reader: std.Io.File.Reader = .initAdapted(file, io, &read_buffer);
2335 var file_reader: std.Io.File.Reader = .init(file, io, &read_buffer);
23362336
23372337 var buf: [4]u8 = undefined;
23382338 try file_reader.interface.readSliceAll(&buf);
......@@ -2347,7 +2347,7 @@ test "File.Writer sendfile with buffered contents" {
23472347
23482348 {
23492349 try tmp_dir.dir.writeFile(.{ .sub_path = "a", .data = "bcd" });
2350 const in = try tmp_dir.dir.openFile("a", .{});
2350 const in = try tmp_dir.dir.openFile(io, "a", .{});
23512351 defer in.close(io);
23522352 const out = try tmp_dir.dir.createFile("b", .{});
23532353 defer out.close(io);
......@@ -2364,7 +2364,7 @@ test "File.Writer sendfile with buffered contents" {
23642364 try out_w.interface.flush();
23652365 }
23662366
2367 var check = try tmp_dir.dir.openFile("b", .{});
2367 var check = try tmp_dir.dir.openFile(io, "b", .{});
23682368 defer check.close(io);
23692369 var check_buf: [4]u8 = undefined;
23702370 var check_r = check.reader(io, &check_buf);
lib/std/os/linux/IoUring.zig+3-3
......@@ -3002,7 +3002,7 @@ test "renameat" {
30023002 }, cqe);
30033003
30043004 // Validate that the old file doesn't exist anymore
3005 try testing.expectError(error.FileNotFound, tmp.dir.openFile(old_path, .{}));
3005 try testing.expectError(error.FileNotFound, tmp.dir.openFile(io, old_path, .{}));
30063006
30073007 // Validate that the new file exists with the proper content
30083008 var new_file_data: [16]u8 = undefined;
......@@ -3057,7 +3057,7 @@ test "unlinkat" {
30573057 }, cqe);
30583058
30593059 // Validate that the file doesn't exist anymore
3060 _ = tmp.dir.openFile(path, .{}) catch |err| switch (err) {
3060 _ = tmp.dir.openFile(io, path, .{}) catch |err| switch (err) {
30613061 error.FileNotFound => {},
30623062 else => std.debug.panic("unexpected error: {}", .{err}),
30633063 };
......@@ -3154,7 +3154,7 @@ test "symlinkat" {
31543154 }, cqe);
31553155
31563156 // Validate that the symlink exist
3157 _ = try tmp.dir.openFile(link_path, .{});
3157 _ = try tmp.dir.openFile(io, link_path, .{});
31583158}
31593159
31603160test "linkat" {
lib/std/posix/test.zig+4-4
......@@ -164,10 +164,10 @@ test "linkat with different directories" {
164164 // Test 1: link from file in subdir back up to target in parent directory
165165 try posix.linkat(tmp.dir.fd, target_name, subdir.fd, link_name, 0);
166166
167 const efd = try tmp.dir.openFile(target_name, .{});
167 const efd = try tmp.dir.openFile(io, target_name, .{});
168168 defer efd.close(io);
169169
170 const nfd = try subdir.openFile(link_name, .{});
170 const nfd = try subdir.openFile(io, link_name, .{});
171171 defer nfd.close(io);
172172
173173 {
......@@ -429,7 +429,7 @@ test "mmap" {
429429
430430 // Map the whole file
431431 {
432 const file = try tmp.dir.openFile(test_out_file, .{});
432 const file = try tmp.dir.openFile(io, test_out_file, .{});
433433 defer file.close(io);
434434
435435 const data = try posix.mmap(
......@@ -454,7 +454,7 @@ test "mmap" {
454454
455455 // Map the upper half of the file
456456 {
457 const file = try tmp.dir.openFile(test_out_file, .{});
457 const file = try tmp.dir.openFile(io, test_out_file, .{});
458458 defer file.close(io);
459459
460460 const data = try posix.mmap(
lib/std/zig/system.zig+3-3
......@@ -817,7 +817,7 @@ fn glibcVerFromRPath(io: Io, rpath: []const u8) !std.SemanticVersion {
817817 // .dynstr section, and finding the max version number of symbols
818818 // that start with "GLIBC_2.".
819819 const glibc_so_basename = "libc.so.6";
820 var file = dir.openFile(glibc_so_basename, .{}) catch |err| switch (err) {
820 var file = dir.openFile(io, glibc_so_basename, .{}) catch |err| switch (err) {
821821 error.NameTooLong => return error.Unexpected,
822822 error.BadPathName => return error.Unexpected,
823823 error.PipeBusy => return error.Unexpected, // Windows-only
......@@ -851,7 +851,7 @@ fn glibcVerFromRPath(io: Io, rpath: []const u8) !std.SemanticVersion {
851851
852852 // Empirically, glibc 2.34 libc.so .dynstr section is 32441 bytes on my system.
853853 var buffer: [8000]u8 = undefined;
854 var file_reader: Io.File.Reader = .initAdapted(file, io, &buffer);
854 var file_reader: Io.File.Reader = .init(file, io, &buffer);
855855
856856 return glibcVerFromSoFile(&file_reader) catch |err| switch (err) {
857857 error.InvalidElfMagic,
......@@ -1053,7 +1053,7 @@ fn detectAbiAndDynamicLinker(io: Io, cpu: Target.Cpu, os: Target.Os, query: Targ
10531053 var is_elf_file = false;
10541054 defer if (!is_elf_file) file.close(io);
10551055
1056 file_reader = .initAdapted(file, io, &file_reader_buffer);
1056 file_reader = .init(file, io, &file_reader_buffer);
10571057 file_name = undefined; // it aliases file_reader_buffer
10581058
10591059 const header = elf.Header.read(&file_reader.interface) catch |hdr_err| switch (hdr_err) {
src/Compilation.zig+4-4
......@@ -1104,7 +1104,7 @@ pub const CObject = struct {
11041104 const source_line = source_line: {
11051105 if (diag.src_loc.offset == 0 or diag.src_loc.column == 0) break :source_line 0;
11061106
1107 const file = fs.cwd().openFile(file_name, .{}) catch break :source_line 0;
1107 const file = fs.cwd().openFile(io, file_name, .{}) catch break :source_line 0;
11081108 defer file.close(io);
11091109 var buffer: [1024]u8 = undefined;
11101110 var file_reader = file.reader(io, &buffer);
......@@ -1179,7 +1179,7 @@ pub const CObject = struct {
11791179 };
11801180
11811181 var buffer: [1024]u8 = undefined;
1182 const file = try fs.cwd().openFile(path, .{});
1182 const file = try fs.cwd().openFile(io, path, .{});
11831183 defer file.close(io);
11841184 var file_reader = file.reader(io, &buffer);
11851185 var bc = std.zig.llvm.BitcodeReader.init(gpa, .{ .reader = &file_reader.interface });
......@@ -5354,14 +5354,14 @@ fn docsCopyModule(
53545354 },
53555355 else => continue,
53565356 }
5357 var file = mod_dir.openFile(entry.path, .{}) catch |err| {
5357 var file = mod_dir.openFile(io, entry.path, .{}) catch |err| {
53585358 return comp.lockAndSetMiscFailure(.docs_copy, "unable to open {f}{s}: {t}", .{
53595359 root.fmt(comp), entry.path, err,
53605360 });
53615361 };
53625362 defer file.close(io);
53635363 const stat = try file.stat();
5364 var file_reader: Io.File.Reader = .initSize(file.adaptToNewApi(), io, &buffer, stat.size);
5364 var file_reader: Io.File.Reader = .initSize(file, io, &buffer, stat.size);
53655365
53665366 archiver.writeFileTimestamp(entry.path, &file_reader, stat.mtime) catch |err| {
53675367 return comp.lockAndSetMiscFailure(.docs_copy, "unable to archive {f}{s}: {t}", .{
src/Package/Fetch.zig+3-3
......@@ -390,7 +390,7 @@ pub fn run(f: *Fetch) RunError!void {
390390 var server_header_buffer: [init_resource_buffer_size]u8 = undefined;
391391
392392 const file_err = if (dir_err == error.NotDir) e: {
393 if (fs.cwd().openFile(path_or_url, .{})) |file| {
393 if (fs.cwd().openFile(io, path_or_url, .{})) |file| {
394394 var resource: Resource = .{ .file = file.reader(io, &server_header_buffer) };
395395 return f.runResource(path_or_url, &resource, null);
396396 } else |err| break :e err;
......@@ -995,7 +995,7 @@ fn initResource(f: *Fetch, uri: std.Uri, resource: *Resource, reader_buffer: []u
995995
996996 if (ascii.eqlIgnoreCase(uri.scheme, "file")) {
997997 const path = try uri.path.toRawMaybeAlloc(arena);
998 const file = f.parent_package_root.openFile(path, .{}) catch |err| {
998 const file = f.parent_package_root.openFile(io, path, .{}) catch |err| {
999999 return f.fail(f.location_tok, try eb.printString("unable to open '{f}{s}': {t}", .{
10001000 f.parent_package_root, path, err,
10011001 }));
......@@ -1677,7 +1677,7 @@ fn hashFileFallible(io: Io, dir: Io.Dir, hashed_file: *HashedFile) HashedFile.Er
16771677
16781678 switch (hashed_file.kind) {
16791679 .file => {
1680 var file = try dir.openFile(hashed_file.fs_path, .{});
1680 var file = try dir.openFile(io, hashed_file.fs_path, .{});
16811681 defer file.close(io);
16821682 // Hard-coded false executable bit: https://github.com/ziglang/zig/issues/17463
16831683 hasher.update(&.{ 0, 0 });
src/Package/Fetch/git.zig+1-1
......@@ -1714,7 +1714,7 @@ pub fn main() !void {
17141714
17151715 const format = std.meta.stringToEnum(Oid.Format, args[1]) orelse return error.InvalidFormat;
17161716
1717 var pack_file = try std.fs.cwd().openFile(args[2], .{});
1717 var pack_file = try std.fs.cwd().openFile(io, args[2], .{});
17181718 defer pack_file.close(io);
17191719 var pack_file_buffer: [4096]u8 = undefined;
17201720 var pack_file_reader = pack_file.reader(io, &pack_file_buffer);
src/Zcu.zig+1-1
......@@ -1076,7 +1076,7 @@ pub const File = struct {
10761076
10771077 var f = f: {
10781078 const dir, const sub_path = file.path.openInfo(zcu.comp.dirs);
1079 break :f try dir.openFile(sub_path, .{});
1079 break :f try dir.openFile(io, sub_path, .{});
10801080 };
10811081 defer f.close(io);
10821082
src/Zcu/PerThread.zig+2-2
......@@ -94,7 +94,7 @@ pub fn updateFile(
9494 // In any case we need to examine the stat of the file to determine the course of action.
9595 var source_file = f: {
9696 const dir, const sub_path = file.path.openInfo(comp.dirs);
97 break :f try dir.openFile(sub_path, .{});
97 break :f try dir.openFile(io, sub_path, .{});
9898 };
9999 defer source_file.close(io);
100100
......@@ -2466,7 +2466,7 @@ fn updateEmbedFileInner(
24662466
24672467 var file = f: {
24682468 const dir, const sub_path = ef.path.openInfo(zcu.comp.dirs);
2469 break :f try dir.openFile(sub_path, .{});
2469 break :f try dir.openFile(io, sub_path, .{});
24702470 };
24712471 defer file.close(io);
24722472
src/fmt.zig+1-1
......@@ -262,7 +262,7 @@ fn fmtPathFile(
262262) !void {
263263 const io = fmt.io;
264264
265 const source_file = try dir.openFile(sub_path, .{});
265 const source_file = try dir.openFile(io, sub_path, .{});
266266 var file_closed = false;
267267 errdefer if (!file_closed) source_file.close(io);
268268
src/introspect.zig+2-2
......@@ -22,7 +22,7 @@ fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory {
2222 // Try lib/zig/std/std.zig
2323 const lib_zig = "lib" ++ fs.path.sep_str ++ "zig";
2424 var test_zig_dir = base_dir.openDir(lib_zig, .{}) catch break :zig_dir;
25 const file = test_zig_dir.openFile(test_index_file, .{}) catch {
25 const file = test_zig_dir.openFile(io, test_index_file, .{}) catch {
2626 test_zig_dir.close(io);
2727 break :zig_dir;
2828 };
......@@ -32,7 +32,7 @@ fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory {
3232
3333 // Try lib/std/std.zig
3434 var test_zig_dir = base_dir.openDir("lib", .{}) catch return null;
35 const file = test_zig_dir.openFile(test_index_file, .{}) catch {
35 const file = test_zig_dir.openFile(io, test_index_file, .{}) catch {
3636 test_zig_dir.close(io);
3737 return null;
3838 };
src/link.zig+12-12
......@@ -637,7 +637,7 @@ pub const File = struct {
637637 }
638638 }
639639 }
640 base.file = try emit.root_dir.handle.openFile(emit.sub_path, .{ .mode = .read_write });
640 base.file = try emit.root_dir.handle.openFile(io, emit.sub_path, .{ .mode = .read_write });
641641 },
642642 .elf2, .coff2 => if (base.file == null) {
643643 const mf = if (base.cast(.elf2)) |elf|
......@@ -646,10 +646,10 @@ pub const File = struct {
646646 &coff.mf
647647 else
648648 unreachable;
649 mf.file = try base.emit.root_dir.handle.adaptToNewApi().openFile(io, base.emit.sub_path, .{
649 mf.file = try base.emit.root_dir.handle.openFile(io, base.emit.sub_path, .{
650650 .mode = .read_write,
651651 });
652 base.file = .adaptFromNewApi(mf.file);
652 base.file = mf.file;
653653 try mf.ensureTotalCapacity(@intCast(mf.nodes.items[0].location().resolve(mf)[1]));
654654 },
655655 .c, .spirv => dev.checkAny(&.{ .c_linker, .spirv_linker }),
......@@ -2007,7 +2007,7 @@ fn resolveLibInput(
20072007 .sub_path = try std.fmt.allocPrint(arena, "lib{s}.tbd", .{lib_name}),
20082008 };
20092009 try checked_paths.print(gpa, "\n {f}", .{test_path});
2010 var file = test_path.root_dir.handle.openFile(test_path.sub_path, .{}) catch |err| switch (err) {
2010 var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) {
20112011 error.FileNotFound => break :tbd,
20122012 else => |e| fatal("unable to search for tbd library '{f}': {s}", .{ test_path, @errorName(e) }),
20132013 };
......@@ -2043,7 +2043,7 @@ fn resolveLibInput(
20432043 .sub_path = try std.fmt.allocPrint(arena, "lib{s}.so", .{lib_name}),
20442044 };
20452045 try checked_paths.print(gpa, "\n {f}", .{test_path});
2046 var file = test_path.root_dir.handle.openFile(test_path.sub_path, .{}) catch |err| switch (err) {
2046 var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) {
20472047 error.FileNotFound => break :so,
20482048 else => |e| fatal("unable to search for so library '{f}': {s}", .{
20492049 test_path, @errorName(e),
......@@ -2061,7 +2061,7 @@ fn resolveLibInput(
20612061 .sub_path = try std.fmt.allocPrint(arena, "lib{s}.a", .{lib_name}),
20622062 };
20632063 try checked_paths.print(gpa, "\n {f}", .{test_path});
2064 var file = test_path.root_dir.handle.openFile(test_path.sub_path, .{}) catch |err| switch (err) {
2064 var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) {
20652065 error.FileNotFound => break :mingw,
20662066 else => |e| fatal("unable to search for static library '{f}': {s}", .{ test_path, @errorName(e) }),
20672067 };
......@@ -2115,7 +2115,7 @@ fn resolvePathInput(
21152115 .static_library => return try resolvePathInputLib(gpa, arena, io, unresolved_inputs, resolved_inputs, ld_script_bytes, target, pq, .static, color),
21162116 .shared_library => return try resolvePathInputLib(gpa, arena, io, unresolved_inputs, resolved_inputs, ld_script_bytes, target, pq, .dynamic, color),
21172117 .object => {
2118 var file = pq.path.root_dir.handle.openFile(pq.path.sub_path, .{}) catch |err|
2118 var file = pq.path.root_dir.handle.openFile(io, pq.path.sub_path, .{}) catch |err|
21192119 fatal("failed to open object {f}: {s}", .{ pq.path, @errorName(err) });
21202120 errdefer file.close(io);
21212121 try resolved_inputs.append(gpa, .{ .object = .{
......@@ -2127,7 +2127,7 @@ fn resolvePathInput(
21272127 return null;
21282128 },
21292129 .res => {
2130 var file = pq.path.root_dir.handle.openFile(pq.path.sub_path, .{}) catch |err|
2130 var file = pq.path.root_dir.handle.openFile(io, pq.path.sub_path, .{}) catch |err|
21312131 fatal("failed to open windows resource {f}: {s}", .{ pq.path, @errorName(err) });
21322132 errdefer file.close(io);
21332133 try resolved_inputs.append(gpa, .{ .res = .{
......@@ -2164,7 +2164,7 @@ fn resolvePathInputLib(
21642164 .static_library, .shared_library => true,
21652165 else => false,
21662166 }) {
2167 var file = test_path.root_dir.handle.openFile(test_path.sub_path, .{}) catch |err| switch (err) {
2167 var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) {
21682168 error.FileNotFound => return .no_match,
21692169 else => |e| fatal("unable to search for {s} library '{f}': {s}", .{
21702170 @tagName(link_mode), std.fmt.alt(test_path, .formatEscapeChar), @errorName(e),
......@@ -2242,7 +2242,7 @@ fn resolvePathInputLib(
22422242 return .ok;
22432243 }
22442244
2245 var file = test_path.root_dir.handle.openFile(test_path.sub_path, .{}) catch |err| switch (err) {
2245 var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) {
22462246 error.FileNotFound => return .no_match,
22472247 else => |e| fatal("unable to search for {s} library {f}: {s}", .{
22482248 @tagName(link_mode), test_path, @errorName(e),
......@@ -2253,7 +2253,7 @@ fn resolvePathInputLib(
22532253}
22542254
22552255pub fn openObject(io: Io, path: Path, must_link: bool, hidden: bool) !Input.Object {
2256 var file = try path.root_dir.handle.openFile(path.sub_path, .{});
2256 var file = try path.root_dir.handle.openFile(io, path.sub_path, .{});
22572257 errdefer file.close(io);
22582258 return .{
22592259 .path = path,
......@@ -2264,7 +2264,7 @@ pub fn openObject(io: Io, path: Path, must_link: bool, hidden: bool) !Input.Obje
22642264}
22652265
22662266pub fn openDso(io: Io, path: Path, needed: bool, weak: bool, reexport: bool) !Input.Dso {
2267 var file = try path.root_dir.handle.openFile(path.sub_path, .{});
2267 var file = try path.root_dir.handle.openFile(io, path.sub_path, .{});
22682268 errdefer file.close(io);
22692269 return .{
22702270 .path = path,
src/link/Coff.zig+2-2
......@@ -632,7 +632,7 @@ fn create(
632632 };
633633
634634 const coff = try arena.create(Coff);
635 const file = try path.root_dir.handle.adaptToNewApi().createFile(comp.io, path.sub_path, .{
635 const file = try path.root_dir.handle.createFile(comp.io, path.sub_path, .{
636636 .read = true,
637637 .mode = link.File.determineMode(comp.config.output_mode, comp.config.link_mode),
638638 });
......@@ -644,7 +644,7 @@ fn create(
644644 .comp = comp,
645645 .emit = path,
646646
647 .file = .adaptFromNewApi(file),
647 .file = file,
648648 .gc_sections = false,
649649 .print_gc_sections = false,
650650 .build_id = .none,
src/link/Elf2.zig+8-6
......@@ -928,6 +928,7 @@ fn create(
928928 path: std.Build.Cache.Path,
929929 options: link.File.OpenOptions,
930930) !*Elf {
931 const io = comp.io;
931932 const target = &comp.root_mod.resolved_target.result;
932933 assert(target.ofmt == .elf);
933934 const class: std.elf.CLASS = switch (target.ptrBitWidth()) {
......@@ -973,11 +974,11 @@ fn create(
973974 };
974975
975976 const elf = try arena.create(Elf);
976 const file = try path.root_dir.handle.adaptToNewApi().createFile(comp.io, path.sub_path, .{
977 const file = try path.root_dir.handle.createFile(io, path.sub_path, .{
977978 .read = true,
978979 .mode = link.File.determineMode(comp.config.output_mode, comp.config.link_mode),
979980 });
980 errdefer file.close(comp.io);
981 errdefer file.close(io);
981982 elf.* = .{
982983 .base = .{
983984 .tag = .elf2,
......@@ -985,7 +986,7 @@ fn create(
985986 .comp = comp,
986987 .emit = path,
987988
988 .file = .adaptFromNewApi(file),
989 .file = file,
989990 .gc_sections = false,
990991 .print_gc_sections = false,
991992 .build_id = .none,
......@@ -3325,12 +3326,13 @@ fn flushInputSection(elf: *Elf, isi: Node.InputSectionIndex) !void {
33253326 const file_loc = isi.fileLocation(elf);
33263327 if (file_loc.size == 0) return;
33273328 const comp = elf.base.comp;
3329 const io = comp.io;
33283330 const gpa = comp.gpa;
33293331 const ii = isi.input(elf);
33303332 const path = ii.path(elf);
3331 const file = try path.root_dir.handle.adaptToNewApi().openFile(comp.io, path.sub_path, .{});
3332 defer file.close(comp.io);
3333 var fr = file.reader(comp.io, &.{});
3333 const file = try path.root_dir.handle.openFile(io, path.sub_path, .{});
3334 defer file.close(io);
3335 var fr = file.reader(io, &.{});
33343336 try fr.seekTo(file_loc.offset);
33353337 var nw: MappedFile.Node.Writer = undefined;
33363338 const si = isi.symbol(elf);
src/link/MachO.zig+5-3
......@@ -1126,7 +1126,9 @@ fn parseDependentDylibs(self: *MachO) !void {
11261126
11271127 if (self.dylibs.items.len == 0) return;
11281128
1129 const gpa = self.base.comp.gpa;
1129 const comp = self.base.comp;
1130 const gpa = comp.gpa;
1131 const io = comp.io;
11301132 const framework_dirs = self.framework_dirs;
11311133
11321134 // TODO delete this, directories must instead be resolved by the frontend
......@@ -1183,7 +1185,7 @@ fn parseDependentDylibs(self: *MachO) !void {
11831185 const path = if (existing_ext.len > 0) id.name[0 .. id.name.len - existing_ext.len] else id.name;
11841186 for (&[_][]const u8{ ".tbd", ".dylib", "" }) |ext| {
11851187 test_path.clearRetainingCapacity();
1186 if (self.base.comp.sysroot) |root| {
1188 if (comp.sysroot) |root| {
11871189 try test_path.print("{s}" ++ fs.path.sep_str ++ "{s}{s}", .{ root, path, ext });
11881190 } else {
11891191 try test_path.print("{s}{s}", .{ path, ext });
......@@ -1235,7 +1237,7 @@ fn parseDependentDylibs(self: *MachO) !void {
12351237 .path = Path.initCwd(full_path),
12361238 .weak = is_weak,
12371239 };
1238 const file = try lib.path.root_dir.handle.openFile(lib.path.sub_path, .{});
1240 const file = try lib.path.root_dir.handle.openFile(io, lib.path.sub_path, .{});
12391241 const fh = try self.addFileHandle(file);
12401242 const fat_arch = try self.parseFatFile(file, lib.path);
12411243 const offset = if (fat_arch) |fa| fa.offset else 0;
src/link/MachO/relocatable.zig+4-3
......@@ -1,6 +1,7 @@
11pub fn flushObject(macho_file: *MachO, comp: *Compilation, module_obj_path: ?Path) link.File.FlushError!void {
2 const gpa = macho_file.base.comp.gpa;
3 const diags = &macho_file.base.comp.link_diags;
2 const gpa = comp.gpa;
3 const io = comp.io;
4 const diags = &comp.link_diags;
45
56 // TODO: "positional arguments" is a CLI concept, not a linker concept. Delete this unnecessary array list.
67 var positionals = std.array_list.Managed(link.Input).init(gpa);
......@@ -19,7 +20,7 @@ pub fn flushObject(macho_file: *MachO, comp: *Compilation, module_obj_path: ?Pat
1920 // debug info segments/sections (this is apparently by design by Apple), we copy
2021 // the *only* input file over.
2122 const path = positionals.items[0].path().?;
22 const in_file = path.root_dir.handle.openFile(path.sub_path, .{}) catch |err|
23 const in_file = path.root_dir.handle.openFile(io, path.sub_path, .{}) catch |err|
2324 return diags.fail("failed to open {f}: {s}", .{ path, @errorName(err) });
2425 const stat = in_file.stat() catch |err|
2526 return diags.fail("failed to stat {f}: {s}", .{ path, @errorName(err) });
src/link/MappedFile.zig+1-1
......@@ -630,7 +630,7 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested
630630 // Resize the entire file
631631 if (ni == Node.Index.root) {
632632 try mf.ensureCapacityForSetLocation(gpa);
633 try Io.File.adaptFromNewApi(mf.file).setEndPos(new_size);
633 try mf.file.setEndPos(new_size);
634634 try mf.ensureTotalCapacity(@intCast(new_size));
635635 ni.setLocationAssumeCapacity(mf, old_offset, new_size);
636636 return;
src/main.zig+5-5
......@@ -4681,7 +4681,7 @@ fn cmdTranslateC(
46814681 } else {
46824682 const hex_digest = Cache.binToHex(result.digest);
46834683 const out_zig_path = try fs.path.join(arena, &.{ "o", &hex_digest, translated_basename });
4684 const zig_file = comp.dirs.local_cache.handle.openFile(out_zig_path, .{}) catch |err| {
4684 const zig_file = comp.dirs.local_cache.handle.openFile(io, out_zig_path, .{}) catch |err| {
46854685 const path = comp.dirs.local_cache.path orelse ".";
46864686 fatal("unable to open cached translated zig file '{s}{s}{s}': {s}", .{
46874687 path,
......@@ -6187,7 +6187,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
61876187 const display_path = zig_source_path orelse "<stdin>";
61886188 const source: [:0]const u8 = s: {
61896189 var f = if (zig_source_path) |p| file: {
6190 break :file fs.cwd().openFile(p, .{}) catch |err| {
6190 break :file fs.cwd().openFile(io, p, .{}) catch |err| {
61916191 fatal("unable to open file '{s}' for ast-check: {s}", .{ display_path, @errorName(err) });
61926192 };
61936193 } else Io.File.stdin();
......@@ -6494,7 +6494,7 @@ fn cmdDumpZir(arena: Allocator, io: Io, args: []const []const u8) !void {
64946494
64956495 const cache_file = args[0];
64966496
6497 var f = fs.cwd().openFile(cache_file, .{}) catch |err| {
6497 var f = fs.cwd().openFile(io, cache_file, .{}) catch |err| {
64986498 fatal("unable to open zir cache file for dumping '{s}': {s}", .{ cache_file, @errorName(err) });
64996499 };
65006500 defer f.close(io);
......@@ -6541,7 +6541,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {
65416541 const new_source_path = args[1];
65426542
65436543 const old_source = source: {
6544 var f = fs.cwd().openFile(old_source_path, .{}) catch |err|
6544 var f = fs.cwd().openFile(io, old_source_path, .{}) catch |err|
65456545 fatal("unable to open old source file '{s}': {s}", .{ old_source_path, @errorName(err) });
65466546 defer f.close(io);
65476547 var file_reader: Io.File.Reader = f.reader(io, &stdin_buffer);
......@@ -6549,7 +6549,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {
65496549 fatal("unable to read old source file '{s}': {s}", .{ old_source_path, @errorName(err) });
65506550 };
65516551 const new_source = source: {
6552 var f = fs.cwd().openFile(new_source_path, .{}) catch |err|
6552 var f = fs.cwd().openFile(io, new_source_path, .{}) catch |err|
65536553 fatal("unable to open new source file '{s}': {s}", .{ new_source_path, @errorName(err) });
65546554 defer f.close(io);
65556555 var file_reader: Io.File.Reader = f.reader(io, &stdin_buffer);