authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-08 17:45:17-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:08-08:00
log4be8be1d2bd6959efae7df95e3f5713adf953a42
treeee9fb0f267e80ba20d4ae26e1ee61c5c348a08da
parent4218344dd3178f2fd3d9d00e9ff6895ee344df6d

update all rename() to rename(io)


23 files changed, 88 insertions(+), 84 deletions(-)

lib/compiler/build_runner.zig+4-4
...@@ -478,14 +478,14 @@ pub fn main() !void {...@@ -478,14 +478,14 @@ pub fn main() !void {
478 validateSystemLibraryOptions(builder);478 validateSystemLibraryOptions(builder);
479479
480 if (help_menu) {480 if (help_menu) {
481 var w = initStdoutWriter();481 var w = initStdoutWriter(io);
482 printUsage(builder, w) catch return stdout_writer_allocation.err.?;482 printUsage(builder, w) catch return stdout_writer_allocation.err.?;
483 w.flush() catch return stdout_writer_allocation.err.?;483 w.flush() catch return stdout_writer_allocation.err.?;
484 return;484 return;
485 }485 }
486486
487 if (steps_menu) {487 if (steps_menu) {
488 var w = initStdoutWriter();488 var w = initStdoutWriter(io);
489 printSteps(builder, w) catch return stdout_writer_allocation.err.?;489 printSteps(builder, w) catch return stdout_writer_allocation.err.?;
490 w.flush() catch return stdout_writer_allocation.err.?;490 w.flush() catch return stdout_writer_allocation.err.?;
491 return;491 return;
...@@ -1847,7 +1847,7 @@ fn createModuleDependenciesForStep(step: *Step) Allocator.Error!void {...@@ -1847,7 +1847,7 @@ fn createModuleDependenciesForStep(step: *Step) Allocator.Error!void {
1847var stdio_buffer_allocation: [256]u8 = undefined;1847var stdio_buffer_allocation: [256]u8 = undefined;
1848var stdout_writer_allocation: Io.File.Writer = undefined;1848var stdout_writer_allocation: Io.File.Writer = undefined;
18491849
1850fn initStdoutWriter() *Writer {1850fn initStdoutWriter(io: Io) *Writer {
1851 stdout_writer_allocation = Io.File.stdout().writerStreaming(&stdio_buffer_allocation);1851 stdout_writer_allocation = Io.File.stdout().writerStreaming(io, &stdio_buffer_allocation);
1852 return &stdout_writer_allocation.interface;1852 return &stdout_writer_allocation.interface;
1853}1853}
lib/compiler/objcopy.zig+1-1
...@@ -183,7 +183,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void...@@ -183,7 +183,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
183 var output_file = try Io.Dir.cwd().createFile(io, output, .{ .mode = mode });183 var output_file = try Io.Dir.cwd().createFile(io, output, .{ .mode = mode });
184 defer output_file.close(io);184 defer output_file.close(io);
185185
186 var out = output_file.writer(&output_buffer);186 var out = output_file.writer(io, &output_buffer);
187187
188 switch (out_fmt) {188 switch (out_fmt) {
189 .hex, .raw => {189 .hex, .raw => {
lib/std/Build/Cache.zig+2-2
...@@ -1134,13 +1134,13 @@ pub const Manifest = struct {...@@ -1134,13 +1134,13 @@ pub const Manifest = struct {
1134 /// lock from exclusive to shared.1134 /// lock from exclusive to shared.
1135 pub fn writeManifest(self: *Manifest) !void {1135 pub fn writeManifest(self: *Manifest) !void {
1136 assert(self.have_exclusive_lock);1136 assert(self.have_exclusive_lock);
11371137 const io = self.cache.io;
1138 const manifest_file = self.manifest_file.?;1138 const manifest_file = self.manifest_file.?;
1139 if (self.manifest_dirty) {1139 if (self.manifest_dirty) {
1140 self.manifest_dirty = false;1140 self.manifest_dirty = false;
11411141
1142 var buffer: [4000]u8 = undefined;1142 var buffer: [4000]u8 = undefined;
1143 var fw = manifest_file.writer(&buffer);1143 var fw = manifest_file.writer(io, &buffer);
1144 writeDirtyManifestToStream(self, &fw) catch |err| switch (err) {1144 writeDirtyManifestToStream(self, &fw) catch |err| switch (err) {
1145 error.WriteFailed => return fw.err.?,1145 error.WriteFailed => return fw.err.?,
1146 else => |e| return e,1146 else => |e| return e,
lib/std/Build/Fuzz.zig+1
...@@ -389,6 +389,7 @@ fn prepareTables(fuzz: *Fuzz, run_step: *Step.Run, coverage_id: u64) error{ OutO...@@ -389,6 +389,7 @@ fn prepareTables(fuzz: *Fuzz, run_step: *Step.Run, coverage_id: u64) error{ OutO
389 const target = run_step.producer.?.rootModuleTarget();389 const target = run_step.producer.?.rootModuleTarget();
390 var debug_info = std.debug.Info.load(390 var debug_info = std.debug.Info.load(
391 fuzz.gpa,391 fuzz.gpa,
392 io,
392 rebuilt_exe_path,393 rebuilt_exe_path,
393 &gop.value_ptr.coverage,394 &gop.value_ptr.coverage,
394 target.ofmt,395 target.ofmt,
lib/std/Build/Step/Compile.zig+3-3
...@@ -1709,7 +1709,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {...@@ -1709,7 +1709,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
1709 defer b.cache_root.handle.deleteFile(io, tmp_path) catch {1709 defer b.cache_root.handle.deleteFile(io, tmp_path) catch {
1710 // It's fine if the temporary file can't be cleaned up.1710 // It's fine if the temporary file can't be cleaned up.
1711 };1711 };
1712 b.cache_root.handle.rename(io, tmp_path, args_file) catch |rename_err| switch (rename_err) {1712 b.cache_root.handle.rename(tmp_path, b.cache_root.handle, args_file, io) catch |rename_err| switch (rename_err) {
1713 error.PathAlreadyExists => {1713 error.PathAlreadyExists => {
1714 // The args file was created by another concurrent build process.1714 // The args file was created by another concurrent build process.
1715 },1715 },
...@@ -1827,14 +1827,14 @@ pub fn doAtomicSymLinks(...@@ -1827,14 +1827,14 @@ pub fn doAtomicSymLinks(
1827 // sym link for libfoo.so.1 to libfoo.so.1.2.31827 // sym link for libfoo.so.1 to libfoo.so.1.2.3
1828 const major_only_path = b.pathJoin(&.{ out_dir, filename_major_only });1828 const major_only_path = b.pathJoin(&.{ out_dir, filename_major_only });
1829 const cwd: Io.Dir = .cwd();1829 const cwd: Io.Dir = .cwd();
1830 cwd.atomicSymLink(io, out_basename, major_only_path, .{}) catch |err| {1830 cwd.symLinkAtomic(io, out_basename, major_only_path, .{}) catch |err| {
1831 return step.fail("unable to symlink {s} -> {s}: {s}", .{1831 return step.fail("unable to symlink {s} -> {s}: {s}", .{
1832 major_only_path, out_basename, @errorName(err),1832 major_only_path, out_basename, @errorName(err),
1833 });1833 });
1834 };1834 };
1835 // sym link for libfoo.so to libfoo.so.11835 // sym link for libfoo.so to libfoo.so.1
1836 const name_only_path = b.pathJoin(&.{ out_dir, filename_name_only });1836 const name_only_path = b.pathJoin(&.{ out_dir, filename_name_only });
1837 cwd.atomicSymLink(io, filename_major_only, name_only_path, .{}) catch |err| {1837 cwd.symLinkAtomic(io, filename_major_only, name_only_path, .{}) catch |err| {
1838 return step.fail("Unable to symlink {s} -> {s}: {s}", .{1838 return step.fail("Unable to symlink {s} -> {s}: {s}", .{
1839 name_only_path, filename_major_only, @errorName(err),1839 name_only_path, filename_major_only, @errorName(err),
1840 });1840 });
lib/std/Build/Step/Options.zig+1-1
...@@ -498,7 +498,7 @@ fn make(step: *Step, make_options: Step.MakeOptions) !void {...@@ -498,7 +498,7 @@ fn make(step: *Step, make_options: Step.MakeOptions) !void {
498 });498 });
499 };499 };
500500
501 b.cache_root.handle.rename(io, tmp_sub_path, sub_path) catch |err| switch (err) {501 b.cache_root.handle.rename(tmp_sub_path, b.cache_root.handle, sub_path, io) catch |err| switch (err) {
502 error.PathAlreadyExists => {502 error.PathAlreadyExists => {
503 // Other process beat us to it. Clean up the temp file.503 // Other process beat us to it. Clean up the temp file.
504 b.cache_root.handle.deleteFile(io, tmp_sub_path) catch |e| {504 b.cache_root.handle.deleteFile(io, tmp_sub_path) catch |e| {
lib/std/Build/Step/Run.zig+8-14
...@@ -1042,27 +1042,21 @@ fn make(step: *Step, options: Step.MakeOptions) !void {...@@ -1042,27 +1042,21 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
1042 if (any_output) {1042 if (any_output) {
1043 const o_sub_path = "o" ++ fs.path.sep_str ++ &digest;1043 const o_sub_path = "o" ++ fs.path.sep_str ++ &digest;
10441044
1045 b.cache_root.handle.rename(tmp_dir_path, o_sub_path) catch |err| {1045 b.cache_root.handle.rename(tmp_dir_path, b.cache_root.handle, o_sub_path, io) catch |err| {
1046 if (err == error.PathAlreadyExists) {1046 if (err == error.PathAlreadyExists) {
1047 b.cache_root.handle.deleteTree(o_sub_path) catch |del_err| {1047 b.cache_root.handle.deleteTree(o_sub_path) catch |del_err| {
1048 return step.fail("unable to remove dir '{f}'{s}: {s}", .{1048 return step.fail("unable to remove dir '{f}'{s}: {t}", .{
1049 b.cache_root,1049 b.cache_root, tmp_dir_path, del_err,
1050 tmp_dir_path,
1051 @errorName(del_err),
1052 });1050 });
1053 };1051 };
1054 b.cache_root.handle.rename(tmp_dir_path, o_sub_path) catch |retry_err| {1052 b.cache_root.handle.rename(tmp_dir_path, b.cache_root.handle, o_sub_path, io) catch |retry_err| {
1055 return step.fail("unable to rename dir '{f}{s}' to '{f}{s}': {s}", .{1053 return step.fail("unable to rename dir '{f}{s}' to '{f}{s}': {t}", .{
1056 b.cache_root, tmp_dir_path,1054 b.cache_root, tmp_dir_path, b.cache_root, o_sub_path, retry_err,
1057 b.cache_root, o_sub_path,
1058 @errorName(retry_err),
1059 });1055 });
1060 };1056 };
1061 } else {1057 } else {
1062 return step.fail("unable to rename dir '{f}{s}' to '{f}{s}': {s}", .{1058 return step.fail("unable to rename dir '{f}{s}' to '{f}{s}': {t}", .{
1063 b.cache_root, tmp_dir_path,1059 b.cache_root, tmp_dir_path, b.cache_root, o_sub_path, err,
1064 b.cache_root, o_sub_path,
1065 @errorName(err),
1066 });1060 });
1067 }1061 }
1068 };1062 };
lib/std/Build/WebServer.zig+3-3
...@@ -523,7 +523,7 @@ pub fn serveTarFile(ws: *WebServer, request: *http.Server.Request, paths: []cons...@@ -523,7 +523,7 @@ pub fn serveTarFile(ws: *WebServer, request: *http.Server.Request, paths: []cons
523 if (cached_cwd_path == null) cached_cwd_path = try std.process.getCwdAlloc(gpa);523 if (cached_cwd_path == null) cached_cwd_path = try std.process.getCwdAlloc(gpa);
524 break :cwd cached_cwd_path.?;524 break :cwd cached_cwd_path.?;
525 };525 };
526 try archiver.writeFile(io, path.sub_path, &file_reader, @intCast(stat.mtime.toSeconds()));526 try archiver.writeFile(path.sub_path, &file_reader, @intCast(stat.mtime.toSeconds()));
527 }527 }
528528
529 // intentionally not calling `archiver.finishPedantically`529 // intentionally not calling `archiver.finishPedantically`
...@@ -587,7 +587,7 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim...@@ -587,7 +587,7 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim
587 });587 });
588 defer poller.deinit();588 defer poller.deinit();
589589
590 try child.stdin.?.writeAll(@ptrCast(@as([]const std.zig.Client.Message.Header, &.{590 try child.stdin.?.writeStreamingAll(io, @ptrCast(@as([]const std.zig.Client.Message.Header, &.{
591 .{ .tag = .update, .bytes_len = 0 },591 .{ .tag = .update, .bytes_len = 0 },
592 .{ .tag = .exit, .bytes_len = 0 },592 .{ .tag = .exit, .bytes_len = 0 },
593 })));593 })));
...@@ -638,7 +638,7 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim...@@ -638,7 +638,7 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim
638 child.stdin.?.close(io);638 child.stdin.?.close(io);
639 child.stdin = null;639 child.stdin = null;
640640
641 switch (try child.wait()) {641 switch (try child.wait(io)) {
642 .Exited => |code| {642 .Exited => |code| {
643 if (code != 0) {643 if (code != 0) {
644 log.err(644 log.err(
lib/std/Io.zig+1-1
...@@ -677,7 +677,7 @@ pub const VTable = struct {...@@ -677,7 +677,7 @@ pub const VTable = struct {
677 dirDeleteFile: *const fn (?*anyopaque, Dir, []const u8) Dir.DeleteFileError!void,677 dirDeleteFile: *const fn (?*anyopaque, Dir, []const u8) Dir.DeleteFileError!void,
678 dirDeleteDir: *const fn (?*anyopaque, Dir, []const u8) Dir.DeleteDirError!void,678 dirDeleteDir: *const fn (?*anyopaque, Dir, []const u8) Dir.DeleteDirError!void,
679 dirRename: *const fn (?*anyopaque, old_dir: Dir, old_sub_path: []const u8, new_dir: Dir, new_sub_path: []const u8) Dir.RenameError!void,679 dirRename: *const fn (?*anyopaque, old_dir: Dir, old_sub_path: []const u8, new_dir: Dir, new_sub_path: []const u8) Dir.RenameError!void,
680 dirSymLink: *const fn (?*anyopaque, Dir, target_path: []const u8, sym_link_path: []const u8, Dir.SymLinkFlags) Dir.RenameError!void,680 dirSymLink: *const fn (?*anyopaque, Dir, target_path: []const u8, sym_link_path: []const u8, Dir.SymLinkFlags) Dir.SymLinkError!void,
681 dirReadLink: *const fn (?*anyopaque, Dir, sub_path: []const u8, buffer: []u8) Dir.ReadLinkError!usize,681 dirReadLink: *const fn (?*anyopaque, Dir, sub_path: []const u8, buffer: []u8) Dir.ReadLinkError!usize,
682 dirSetOwner: *const fn (?*anyopaque, Dir, ?File.Uid, ?File.Gid) Dir.SetOwnerError!void,682 dirSetOwner: *const fn (?*anyopaque, Dir, ?File.Uid, ?File.Gid) Dir.SetOwnerError!void,
683 dirSetPermissions: *const fn (?*anyopaque, Dir, Dir.Permissions) Dir.SetPermissionsError!void,683 dirSetPermissions: *const fn (?*anyopaque, Dir, Dir.Permissions) Dir.SetPermissionsError!void,
lib/std/Io/Dir.zig+9-2
...@@ -501,7 +501,7 @@ pub const WriteFileError = File.Writer.Error || File.OpenError;...@@ -501,7 +501,7 @@ pub const WriteFileError = File.Writer.Error || File.OpenError;
501pub fn writeFile(dir: Dir, io: Io, options: WriteFileOptions) WriteFileError!void {501pub fn writeFile(dir: Dir, io: Io, options: WriteFileOptions) WriteFileError!void {
502 var file = try dir.createFile(io, options.sub_path, options.flags);502 var file = try dir.createFile(io, options.sub_path, options.flags);
503 defer file.close(io);503 defer file.close(io);
504 try file.writeAll(io, options.data);504 try file.writeStreamingAll(io, options.data);
505}505}
506506
507pub const PrevStatus = enum {507pub const PrevStatus = enum {
...@@ -955,6 +955,13 @@ pub fn rename(...@@ -955,6 +955,13 @@ pub fn rename(
955 return io.vtable.dirRename(io.userdata, old_dir, old_sub_path, new_dir, new_sub_path);955 return io.vtable.dirRename(io.userdata, old_dir, old_sub_path, new_dir, new_sub_path);
956}956}
957957
958pub fn renameAbsolute(io: Io, old_path: []const u8, new_path: []const u8) RenameError!void {
959 assert(path.isAbsolute(old_path));
960 assert(path.isAbsolute(new_path));
961 const my_cwd = cwd();
962 return io.vtable.dirRename(io.userdata, my_cwd, old_path, my_cwd, new_path);
963}
964
958/// Use with `Dir.symLink`, `Dir.symLinkAtomic`, and `symLinkAbsolute` to965/// Use with `Dir.symLink`, `Dir.symLinkAtomic`, and `symLinkAbsolute` to
959/// specify whether the symlink will point to a file or a directory. This value966/// specify whether the symlink will point to a file or a directory. This value
960/// is ignored on all hosts except Windows where creating symlinks to different967/// is ignored on all hosts except Windows where creating symlinks to different
...@@ -1053,7 +1060,7 @@ pub fn symLinkAtomic(...@@ -1053,7 +1060,7 @@ pub fn symLinkAtomic(
1053 temp_path[dirname.len + 1 ..][0..rand_len].* = std.fmt.hex(random_integer);1060 temp_path[dirname.len + 1 ..][0..rand_len].* = std.fmt.hex(random_integer);
10541061
1055 if (dir.symLink(io, target_path, temp_path, flags)) {1062 if (dir.symLink(io, target_path, temp_path, flags)) {
1056 return dir.rename(temp_path, dir, io, sym_link_path);1063 return dir.rename(temp_path, dir, sym_link_path, io);
1057 } else |err| switch (err) {1064 } else |err| switch (err) {
1058 error.PathAlreadyExists => continue,1065 error.PathAlreadyExists => continue,
1059 else => |e| return e,1066 else => |e| return e,
lib/std/fs/test.zig+19-19
...@@ -961,14 +961,14 @@ test "Dir.rename files" {...@@ -961,14 +961,14 @@ test "Dir.rename files" {
961 const missing_file_path = try ctx.transformPath("missing_file_name");961 const missing_file_path = try ctx.transformPath("missing_file_name");
962 const something_else_path = try ctx.transformPath("something_else");962 const something_else_path = try ctx.transformPath("something_else");
963963
964 try testing.expectError(error.FileNotFound, ctx.dir.rename(missing_file_path, something_else_path));964 try testing.expectError(error.FileNotFound, ctx.dir.rename(missing_file_path, ctx.dir, something_else_path, io));
965965
966 // Renaming files966 // Renaming files
967 const test_file_name = try ctx.transformPath("test_file");967 const test_file_name = try ctx.transformPath("test_file");
968 const renamed_test_file_name = try ctx.transformPath("test_file_renamed");968 const renamed_test_file_name = try ctx.transformPath("test_file_renamed");
969 var file = try ctx.dir.createFile(io, test_file_name, .{ .read = true });969 var file = try ctx.dir.createFile(io, test_file_name, .{ .read = true });
970 file.close(io);970 file.close(io);
971 try ctx.dir.rename(test_file_name, renamed_test_file_name);971 try ctx.dir.rename(test_file_name, ctx.dir, renamed_test_file_name, io);
972972
973 // Ensure the file was renamed973 // Ensure the file was renamed
974 try testing.expectError(error.FileNotFound, ctx.dir.openFile(io, test_file_name, .{}));974 try testing.expectError(error.FileNotFound, ctx.dir.openFile(io, test_file_name, .{}));
...@@ -976,13 +976,13 @@ test "Dir.rename files" {...@@ -976,13 +976,13 @@ test "Dir.rename files" {
976 file.close(io);976 file.close(io);
977977
978 // Rename to self succeeds978 // Rename to self succeeds
979 try ctx.dir.rename(renamed_test_file_name, renamed_test_file_name);979 try ctx.dir.rename(renamed_test_file_name, ctx.dir, renamed_test_file_name, io);
980980
981 // Rename to existing file succeeds981 // Rename to existing file succeeds
982 const existing_file_path = try ctx.transformPath("existing_file");982 const existing_file_path = try ctx.transformPath("existing_file");
983 var existing_file = try ctx.dir.createFile(io, existing_file_path, .{ .read = true });983 var existing_file = try ctx.dir.createFile(io, existing_file_path, .{ .read = true });
984 existing_file.close(io);984 existing_file.close(io);
985 try ctx.dir.rename(renamed_test_file_name, existing_file_path);985 try ctx.dir.rename(renamed_test_file_name, ctx.dir, existing_file_path, io);
986986
987 try testing.expectError(error.FileNotFound, ctx.dir.openFile(io, renamed_test_file_name, .{}));987 try testing.expectError(error.FileNotFound, ctx.dir.openFile(io, renamed_test_file_name, .{}));
988 file = try ctx.dir.openFile(io, existing_file_path, .{});988 file = try ctx.dir.openFile(io, existing_file_path, .{});
...@@ -1007,7 +1007,7 @@ test "Dir.rename directories" {...@@ -1007,7 +1007,7 @@ test "Dir.rename directories" {
10071007
1008 // Renaming directories1008 // Renaming directories
1009 try ctx.dir.makeDir(test_dir_path);1009 try ctx.dir.makeDir(test_dir_path);
1010 try ctx.dir.rename(test_dir_path, test_dir_renamed_path);1010 try ctx.dir.rename(test_dir_path, ctx.dir, test_dir_renamed_path, io);
10111011
1012 // Ensure the directory was renamed1012 // Ensure the directory was renamed
1013 try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_path, .{}));1013 try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_path, .{}));
...@@ -1019,7 +1019,7 @@ test "Dir.rename directories" {...@@ -1019,7 +1019,7 @@ test "Dir.rename directories" {
1019 dir.close(io);1019 dir.close(io);
10201020
1021 const test_dir_renamed_again_path = try ctx.transformPath("test_dir_renamed_again");1021 const test_dir_renamed_again_path = try ctx.transformPath("test_dir_renamed_again");
1022 try ctx.dir.rename(test_dir_renamed_path, test_dir_renamed_again_path);1022 try ctx.dir.rename(test_dir_renamed_path, ctx.dir, test_dir_renamed_again_path, io);
10231023
1024 // Ensure the directory was renamed and the file still exists in it1024 // Ensure the directory was renamed and the file still exists in it
1025 try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_renamed_path, .{}));1025 try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_renamed_path, .{}));
...@@ -1044,7 +1044,7 @@ test "Dir.rename directory onto empty dir" {...@@ -1044,7 +1044,7 @@ test "Dir.rename directory onto empty dir" {
10441044
1045 try ctx.dir.makeDir(test_dir_path);1045 try ctx.dir.makeDir(test_dir_path);
1046 try ctx.dir.makeDir(target_dir_path);1046 try ctx.dir.makeDir(target_dir_path);
1047 try ctx.dir.rename(test_dir_path, target_dir_path);1047 try ctx.dir.rename(test_dir_path, ctx.dir, target_dir_path, io);
10481048
1049 // Ensure the directory was renamed1049 // Ensure the directory was renamed
1050 try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_path, .{}));1050 try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_path, .{}));
...@@ -1072,7 +1072,7 @@ test "Dir.rename directory onto non-empty dir" {...@@ -1072,7 +1072,7 @@ test "Dir.rename directory onto non-empty dir" {
1072 target_dir.close(io);1072 target_dir.close(io);
10731073
1074 // Rename should fail with PathAlreadyExists if target_dir is non-empty1074 // Rename should fail with PathAlreadyExists if target_dir is non-empty
1075 try testing.expectError(error.PathAlreadyExists, ctx.dir.rename(test_dir_path, target_dir_path));1075 try testing.expectError(error.PathAlreadyExists, ctx.dir.rename(test_dir_path, ctx.dir, target_dir_path, io));
10761076
1077 // Ensure the directory was not renamed1077 // Ensure the directory was not renamed
1078 var dir = try ctx.dir.openDir(io, test_dir_path, .{});1078 var dir = try ctx.dir.openDir(io, test_dir_path, .{});
...@@ -1094,8 +1094,8 @@ test "Dir.rename file <-> dir" {...@@ -1094,8 +1094,8 @@ test "Dir.rename file <-> dir" {
1094 var file = try ctx.dir.createFile(io, test_file_path, .{ .read = true });1094 var file = try ctx.dir.createFile(io, test_file_path, .{ .read = true });
1095 file.close(io);1095 file.close(io);
1096 try ctx.dir.makeDir(test_dir_path);1096 try ctx.dir.makeDir(test_dir_path);
1097 try testing.expectError(error.IsDir, ctx.dir.rename(test_file_path, test_dir_path));1097 try testing.expectError(error.IsDir, ctx.dir.rename(test_file_path, ctx.dir, test_dir_path, io));
1098 try testing.expectError(error.NotDir, ctx.dir.rename(test_dir_path, test_file_path));1098 try testing.expectError(error.NotDir, ctx.dir.rename(test_dir_path, ctx.dir, test_file_path, io));
1099 }1099 }
1100 }.impl);1100 }.impl);
1101}1101}
...@@ -1114,7 +1114,7 @@ test "rename" {...@@ -1114,7 +1114,7 @@ test "rename" {
1114 const renamed_test_file_name = "test_file_renamed";1114 const renamed_test_file_name = "test_file_renamed";
1115 var file = try tmp_dir1.dir.createFile(io, test_file_name, .{ .read = true });1115 var file = try tmp_dir1.dir.createFile(io, test_file_name, .{ .read = true });
1116 file.close(io);1116 file.close(io);
1117 try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name);1117 try Dir.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name, io);
11181118
1119 // ensure the file was renamed1119 // ensure the file was renamed
1120 try testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(io, test_file_name, .{}));1120 try testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(io, test_file_name, .{}));
...@@ -1492,7 +1492,7 @@ test "pwritev, preadv" {...@@ -1492,7 +1492,7 @@ test "pwritev, preadv" {
1492 var src_file = try tmp.dir.createFile(io, "test.txt", .{ .read = true });1492 var src_file = try tmp.dir.createFile(io, "test.txt", .{ .read = true });
1493 defer src_file.close(io);1493 defer src_file.close(io);
14941494
1495 var writer = src_file.writer(&.{});1495 var writer = src_file.writer(io, &.{});
14961496
1497 try writer.seekTo(16);1497 try writer.seekTo(16);
1498 try writer.interface.writeVecAll(&lines);1498 try writer.interface.writeVecAll(&lines);
...@@ -1593,7 +1593,7 @@ test "sendfile" {...@@ -1593,7 +1593,7 @@ test "sendfile" {
1593 var src_file = try dir.createFile(io, "sendfile1.txt", .{ .read = true });1593 var src_file = try dir.createFile(io, "sendfile1.txt", .{ .read = true });
1594 defer src_file.close(io);1594 defer src_file.close(io);
1595 {1595 {
1596 var fw = src_file.writer(&.{});1596 var fw = src_file.writer(io, &.{});
1597 try fw.interface.writeVecAll(&vecs);1597 try fw.interface.writeVecAll(&vecs);
1598 }1598 }
15991599
...@@ -1610,7 +1610,7 @@ test "sendfile" {...@@ -1610,7 +1610,7 @@ test "sendfile" {
1610 var written_buf: [100]u8 = undefined;1610 var written_buf: [100]u8 = undefined;
1611 var file_reader = src_file.reader(io, &.{});1611 var file_reader = src_file.reader(io, &.{});
1612 var fallback_buffer: [50]u8 = undefined;1612 var fallback_buffer: [50]u8 = undefined;
1613 var file_writer = dest_file.writer(&fallback_buffer);1613 var file_writer = dest_file.writer(io, &fallback_buffer);
1614 try file_writer.interface.writeVecAll(&headers);1614 try file_writer.interface.writeVecAll(&headers);
1615 try file_reader.seekTo(1);1615 try file_reader.seekTo(1);
1616 try testing.expectEqual(10, try file_writer.interface.sendFileAll(&file_reader, .limited(10)));1616 try testing.expectEqual(10, try file_writer.interface.sendFileAll(&file_reader, .limited(10)));
...@@ -1648,7 +1648,7 @@ test "sendfile with buffered data" {...@@ -1648,7 +1648,7 @@ test "sendfile with buffered data" {
1648 try file_reader.interface.fill(8);1648 try file_reader.interface.fill(8);
16491649
1650 var fallback_buffer: [32]u8 = undefined;1650 var fallback_buffer: [32]u8 = undefined;
1651 var file_writer = dest_file.writer(&fallback_buffer);1651 var file_writer = dest_file.writer(io, &fallback_buffer);
16521652
1653 try std.testing.expectEqual(4, try file_writer.interface.sendFileAll(&file_reader, .limited(4)));1653 try std.testing.expectEqual(4, try file_writer.interface.sendFileAll(&file_reader, .limited(4)));
16541654
...@@ -2051,7 +2051,7 @@ test "'.' and '..' in Io.Dir functions" {...@@ -2051,7 +2051,7 @@ test "'.' and '..' in Io.Dir functions" {
2051 try ctx.dir.access(io, file_path, .{});2051 try ctx.dir.access(io, file_path, .{});
20522052
2053 try ctx.dir.copyFile(file_path, ctx.dir, copy_path, .{});2053 try ctx.dir.copyFile(file_path, ctx.dir, copy_path, .{});
2054 try ctx.dir.rename(copy_path, rename_path);2054 try ctx.dir.rename(copy_path, ctx.dir, rename_path, io);
2055 const renamed_file = try ctx.dir.openFile(io, rename_path, .{});2055 const renamed_file = try ctx.dir.openFile(io, rename_path, .{});
2056 renamed_file.close(io);2056 renamed_file.close(io);
2057 try ctx.dir.deleteFile(rename_path);2057 try ctx.dir.deleteFile(rename_path);
...@@ -2175,7 +2175,7 @@ test "invalid UTF-8/WTF-8 paths" {...@@ -2175,7 +2175,7 @@ test "invalid UTF-8/WTF-8 paths" {
21752175
2176 try testing.expectError(expected_err, ctx.dir.deleteDir(invalid_path));2176 try testing.expectError(expected_err, ctx.dir.deleteDir(invalid_path));
21772177
2178 try testing.expectError(expected_err, ctx.dir.rename(invalid_path, invalid_path));2178 try testing.expectError(expected_err, ctx.dir.rename(invalid_path, ctx.dir, invalid_path, io));
21792179
2180 try testing.expectError(expected_err, ctx.dir.symLink(invalid_path, invalid_path, .{}));2180 try testing.expectError(expected_err, ctx.dir.symLink(invalid_path, invalid_path, .{}));
2181 if (native_os == .wasi) {2181 if (native_os == .wasi) {
...@@ -2208,7 +2208,7 @@ test "invalid UTF-8/WTF-8 paths" {...@@ -2208,7 +2208,7 @@ test "invalid UTF-8/WTF-8 paths" {
2208 try testing.expectError(expected_err, ctx.dir.realpathAlloc(testing.allocator, invalid_path));2208 try testing.expectError(expected_err, ctx.dir.realpathAlloc(testing.allocator, invalid_path));
2209 }2209 }
22102210
2211 try testing.expectError(expected_err, fs.rename(ctx.dir, invalid_path, ctx.dir, invalid_path));2211 try testing.expectError(expected_err, Dir.rename(ctx.dir, invalid_path, ctx.dir, invalid_path, io));
22122212
2213 if (native_os != .wasi and ctx.path_type != .relative) {2213 if (native_os != .wasi and ctx.path_type != .relative) {
2214 try testing.expectError(expected_err, Dir.copyFileAbsolute(invalid_path, invalid_path, .{}));2214 try testing.expectError(expected_err, Dir.copyFileAbsolute(invalid_path, invalid_path, .{}));
...@@ -2334,7 +2334,7 @@ test "seekTo flushes buffered data" {...@@ -2334,7 +2334,7 @@ test "seekTo flushes buffered data" {
2334 defer file.close(io);2334 defer file.close(io);
2335 {2335 {
2336 var buf: [16]u8 = undefined;2336 var buf: [16]u8 = undefined;
2337 var file_writer = File.writer(file, &buf);2337 var file_writer = file.writer(io, file, &buf);
23382338
2339 try file_writer.interface.writeAll(contents);2339 try file_writer.interface.writeAll(contents);
2340 try file_writer.seekTo(8);2340 try file_writer.seekTo(8);
lib/std/posix/test.zig+2-2
...@@ -690,7 +690,7 @@ test "rename smoke test" {...@@ -690,7 +690,7 @@ test "rename smoke test" {
690 // Rename the file690 // Rename the file
691 const new_file_path = try fs.path.join(a, &.{ base_path, "some_other_file" });691 const new_file_path = try fs.path.join(a, &.{ base_path, "some_other_file" });
692 defer a.free(new_file_path);692 defer a.free(new_file_path);
693 try posix.rename(file_path, new_file_path);693 try Io.Dir.renameAbsolute(file_path, new_file_path);
694 }694 }
695695
696 {696 {
...@@ -717,7 +717,7 @@ test "rename smoke test" {...@@ -717,7 +717,7 @@ test "rename smoke test" {
717 // Rename the directory717 // Rename the directory
718 const new_file_path = try fs.path.join(a, &.{ base_path, "some_other_dir" });718 const new_file_path = try fs.path.join(a, &.{ base_path, "some_other_dir" });
719 defer a.free(new_file_path);719 defer a.free(new_file_path);
720 try posix.rename(file_path, new_file_path);720 try Io.Dir.renameAbsolute(file_path, new_file_path);
721 }721 }
722722
723 {723 {
lib/std/tar.zig+1-1
...@@ -612,7 +612,7 @@ pub fn pipeToFileSystem(io: Io, dir: Io.Dir, reader: *Io.Reader, options: PipeOp...@@ -612,7 +612,7 @@ pub fn pipeToFileSystem(io: Io, dir: Io.Dir, reader: *Io.Reader, options: PipeOp
612 .file => {612 .file => {
613 if (createDirAndFile(io, dir, file_name, fileMode(file.mode, options))) |fs_file| {613 if (createDirAndFile(io, dir, file_name, fileMode(file.mode, options))) |fs_file| {
614 defer fs_file.close(io);614 defer fs_file.close(io);
615 var file_writer = fs_file.writer(&file_contents_buffer);615 var file_writer = fs_file.writer(io, &file_contents_buffer);
616 try it.streamRemaining(file, &file_writer.interface);616 try it.streamRemaining(file, &file_writer.interface);
617 try file_writer.interface.flush();617 try file_writer.interface.flush();
618 } else |err| {618 } else |err| {
lib/std/zip.zig+1-1
...@@ -570,7 +570,7 @@ pub const Iterator = struct {...@@ -570,7 +570,7 @@ pub const Iterator = struct {
570 };570 };
571 defer out_file.close(io);571 defer out_file.close(io);
572 var out_file_buffer: [1024]u8 = undefined;572 var out_file_buffer: [1024]u8 = undefined;
573 var file_writer = out_file.writer(&out_file_buffer);573 var file_writer = out_file.writer(io, &out_file_buffer);
574 const local_data_file_offset: u64 =574 const local_data_file_offset: u64 =
575 @as(u64, self.file_offset) +575 @as(u64, self.file_offset) +
576 @as(u64, @sizeOf(LocalFileHeader)) +576 @as(u64, @sizeOf(LocalFileHeader)) +
src/Compilation.zig+3-3
...@@ -5303,7 +5303,7 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {...@@ -5303,7 +5303,7 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {
5303 defer tar_file.close(io);5303 defer tar_file.close(io);
53045304
5305 var buffer: [1024]u8 = undefined;5305 var buffer: [1024]u8 = undefined;
5306 var tar_file_writer = tar_file.writer(&buffer);5306 var tar_file_writer = tar_file.writer(io, &buffer);
53075307
5308 var seen_table: std.AutoArrayHashMapUnmanaged(*Package.Module, []const u8) = .empty;5308 var seen_table: std.AutoArrayHashMapUnmanaged(*Package.Module, []const u8) = .empty;
5309 defer seen_table.deinit(comp.gpa);5309 defer seen_table.deinit(comp.gpa);
...@@ -6448,7 +6448,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr...@@ -6448,7 +6448,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
6448 var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(o_sub_path, .{});6448 var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(o_sub_path, .{});
6449 defer o_dir.close(io);6449 defer o_dir.close(io);
6450 const tmp_basename = fs.path.basename(out_obj_path);6450 const tmp_basename = fs.path.basename(out_obj_path);
6451 try fs.rename(zig_cache_tmp_dir, tmp_basename, o_dir, o_basename);6451 try Io.Dir.rename(zig_cache_tmp_dir, tmp_basename, o_dir, o_basename, io);
6452 break :blk digest;6452 break :blk digest;
6453 };6453 };
64546454
...@@ -6696,7 +6696,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32...@@ -6696,7 +6696,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
6696 var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(o_sub_path, .{});6696 var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(o_sub_path, .{});
6697 defer o_dir.close(io);6697 defer o_dir.close(io);
6698 const tmp_basename = fs.path.basename(out_res_path);6698 const tmp_basename = fs.path.basename(out_res_path);
6699 try fs.rename(zig_cache_tmp_dir, tmp_basename, o_dir, res_filename);6699 try Io.Dir.rename(zig_cache_tmp_dir, tmp_basename, o_dir, res_filename, io);
6700 break :blk digest;6700 break :blk digest;
6701 };6701 };
67026702
src/Package/Fetch.zig+6-6
...@@ -567,7 +567,7 @@ fn runResource(...@@ -567,7 +567,7 @@ fn runResource(
567 .root_dir = cache_root,567 .root_dir = cache_root,
568 .sub_path = try std.fmt.allocPrint(arena, "p" ++ s ++ "{s}", .{computed_package_hash.toSlice()}),568 .sub_path = try std.fmt.allocPrint(arena, "p" ++ s ++ "{s}", .{computed_package_hash.toSlice()}),
569 };569 };
570 renameTmpIntoCache(cache_root.handle, package_sub_path, f.package_root.sub_path) catch |err| {570 renameTmpIntoCache(io, cache_root.handle, package_sub_path, f.package_root.sub_path) catch |err| {
571 const src = try cache_root.join(arena, &.{tmp_dir_sub_path});571 const src = try cache_root.join(arena, &.{tmp_dir_sub_path});
572 const dest = try cache_root.join(arena, &.{f.package_root.sub_path});572 const dest = try cache_root.join(arena, &.{f.package_root.sub_path});
573 try eb.addRootErrorMessage(.{ .msg = try eb.printString(573 try eb.addRootErrorMessage(.{ .msg = try eb.printString(
...@@ -1319,7 +1319,7 @@ fn unzip(...@@ -1319,7 +1319,7 @@ fn unzip(
1319 defer zip_file.close(io);1319 defer zip_file.close(io);
1320 var zip_file_buffer: [4096]u8 = undefined;1320 var zip_file_buffer: [4096]u8 = undefined;
1321 var zip_file_reader = b: {1321 var zip_file_reader = b: {
1322 var zip_file_writer = zip_file.writer(&zip_file_buffer);1322 var zip_file_writer = zip_file.writer(io, &zip_file_buffer);
13231323
1324 _ = reader.streamRemaining(&zip_file_writer.interface) catch |err| switch (err) {1324 _ = reader.streamRemaining(&zip_file_writer.interface) catch |err| switch (err) {
1325 error.ReadFailed => return error.ReadFailed,1325 error.ReadFailed => return error.ReadFailed,
...@@ -1370,7 +1370,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U...@@ -1370,7 +1370,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
1370 defer pack_file.close(io);1370 defer pack_file.close(io);
1371 var pack_file_buffer: [4096]u8 = undefined;1371 var pack_file_buffer: [4096]u8 = undefined;
1372 var pack_file_reader = b: {1372 var pack_file_reader = b: {
1373 var pack_file_writer = pack_file.writer(&pack_file_buffer);1373 var pack_file_writer = pack_file.writer(io, &pack_file_buffer);
1374 const fetch_reader = &resource.fetch_stream.reader;1374 const fetch_reader = &resource.fetch_stream.reader;
1375 _ = try fetch_reader.streamRemaining(&pack_file_writer.interface);1375 _ = try fetch_reader.streamRemaining(&pack_file_writer.interface);
1376 try pack_file_writer.interface.flush();1376 try pack_file_writer.interface.flush();
...@@ -1380,7 +1380,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U...@@ -1380,7 +1380,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
1380 var index_file = try pack_dir.createFile(io, "pkg.idx", .{ .read = true });1380 var index_file = try pack_dir.createFile(io, "pkg.idx", .{ .read = true });
1381 defer index_file.close(io);1381 defer index_file.close(io);
1382 var index_file_buffer: [2000]u8 = undefined;1382 var index_file_buffer: [2000]u8 = undefined;
1383 var index_file_writer = index_file.writer(&index_file_buffer);1383 var index_file_writer = index_file.writer(io, &index_file_buffer);
1384 {1384 {
1385 const index_prog_node = f.prog_node.start("Index pack", 0);1385 const index_prog_node = f.prog_node.start("Index pack", 0);
1386 defer index_prog_node.end();1386 defer index_prog_node.end();
...@@ -1454,11 +1454,11 @@ fn recursiveDirectoryCopy(f: *Fetch, dir: Io.Dir, tmp_dir: Io.Dir) anyerror!void...@@ -1454,11 +1454,11 @@ fn recursiveDirectoryCopy(f: *Fetch, dir: Io.Dir, tmp_dir: Io.Dir) anyerror!void
1454 }1454 }
1455}1455}
14561456
1457pub fn renameTmpIntoCache(cache_dir: Io.Dir, tmp_dir_sub_path: []const u8, dest_dir_sub_path: []const u8) !void {1457pub fn renameTmpIntoCache(io: Io, cache_dir: Io.Dir, tmp_dir_sub_path: []const u8, dest_dir_sub_path: []const u8) !void {
1458 assert(dest_dir_sub_path[1] == fs.path.sep);1458 assert(dest_dir_sub_path[1] == fs.path.sep);
1459 var handled_missing_dir = false;1459 var handled_missing_dir = false;
1460 while (true) {1460 while (true) {
1461 cache_dir.rename(tmp_dir_sub_path, dest_dir_sub_path) catch |err| switch (err) {1461 cache_dir.rename(tmp_dir_sub_path, cache_dir, dest_dir_sub_path, io) catch |err| switch (err) {
1462 error.FileNotFound => {1462 error.FileNotFound => {
1463 if (handled_missing_dir) return err;1463 if (handled_missing_dir) return err;
1464 cache_dir.makeDir(dest_dir_sub_path[0..1]) catch |mkd_err| switch (mkd_err) {1464 cache_dir.makeDir(dest_dir_sub_path[0..1]) catch |mkd_err| switch (mkd_err) {
src/Package/Fetch/git.zig+2-2
...@@ -1594,7 +1594,7 @@ fn runRepositoryTest(io: Io, comptime format: Oid.Format, head_commit: []const u...@@ -1594,7 +1594,7 @@ fn runRepositoryTest(io: Io, comptime format: Oid.Format, head_commit: []const u
1594 var index_file = try git_dir.dir.createFile(io, "testrepo.idx", .{ .read = true });1594 var index_file = try git_dir.dir.createFile(io, "testrepo.idx", .{ .read = true });
1595 defer index_file.close(io);1595 defer index_file.close(io);
1596 var index_file_buffer: [2000]u8 = undefined;1596 var index_file_buffer: [2000]u8 = undefined;
1597 var index_file_writer = index_file.writer(&index_file_buffer);1597 var index_file_writer = index_file.writer(io, &index_file_buffer);
1598 try indexPack(testing.allocator, format, &pack_file_reader, &index_file_writer);1598 try indexPack(testing.allocator, format, &pack_file_reader, &index_file_writer);
15991599
1600 // Arbitrary size limit on files read while checking the repository contents1600 // Arbitrary size limit on files read while checking the repository contents
...@@ -1730,7 +1730,7 @@ pub fn main() !void {...@@ -1730,7 +1730,7 @@ pub fn main() !void {
1730 var index_file = try git_dir.createFile(io, "idx", .{ .read = true });1730 var index_file = try git_dir.createFile(io, "idx", .{ .read = true });
1731 defer index_file.close(io);1731 defer index_file.close(io);
1732 var index_file_buffer: [4096]u8 = undefined;1732 var index_file_buffer: [4096]u8 = undefined;
1733 var index_file_writer = index_file.writer(&index_file_buffer);1733 var index_file_writer = index_file.writer(io, &index_file_buffer);
1734 try indexPack(allocator, format, &pack_file_reader, &index_file_writer);1734 try indexPack(allocator, format, &pack_file_reader, &index_file_writer);
17351735
1736 std.debug.print("Starting checkout...\n", .{});1736 std.debug.print("Starting checkout...\n", .{});
src/Zcu.zig+10-4
...@@ -2986,7 +2986,13 @@ pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_br: *Io.Reader...@@ -2986,7 +2986,13 @@ pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_br: *Io.Reader
2986 return zir;2986 return zir;
2987}2987}
29882988
2989pub fn saveZirCache(gpa: Allocator, cache_file: Io.File, stat: Io.File.Stat, zir: Zir) (Io.File.WriteError || Allocator.Error)!void {2989pub fn saveZirCache(
2990 gpa: Allocator,
2991 io: Io,
2992 cache_file: Io.File,
2993 stat: Io.File.Stat,
2994 zir: Zir,
2995) (Io.File.WriteError || Allocator.Error)!void {
2990 const safety_buffer = if (data_has_safety_tag)2996 const safety_buffer = if (data_has_safety_tag)
2991 try gpa.alloc([8]u8, zir.instructions.len)2997 try gpa.alloc([8]u8, zir.instructions.len)
2992 else2998 else
...@@ -3020,13 +3026,13 @@ pub fn saveZirCache(gpa: Allocator, cache_file: Io.File, stat: Io.File.Stat, zir...@@ -3020,13 +3026,13 @@ pub fn saveZirCache(gpa: Allocator, cache_file: Io.File, stat: Io.File.Stat, zir
3020 zir.string_bytes,3026 zir.string_bytes,
3021 @ptrCast(zir.extra),3027 @ptrCast(zir.extra),
3022 };3028 };
3023 var cache_fw = cache_file.writer(&.{});3029 var cache_fw = cache_file.writer(io, &.{});
3024 cache_fw.interface.writeVecAll(&vecs) catch |err| switch (err) {3030 cache_fw.interface.writeVecAll(&vecs) catch |err| switch (err) {
3025 error.WriteFailed => return cache_fw.err.?,3031 error.WriteFailed => return cache_fw.err.?,
3026 };3032 };
3027}3033}
30283034
3029pub fn saveZoirCache(cache_file: Io.File, stat: Io.File.Stat, zoir: Zoir) Io.File.WriteError!void {3035pub fn saveZoirCache(io: Io, cache_file: Io.File, stat: Io.File.Stat, zoir: Zoir) Io.File.WriteError!void {
3030 const header: Zoir.Header = .{3036 const header: Zoir.Header = .{
3031 .nodes_len = @intCast(zoir.nodes.len),3037 .nodes_len = @intCast(zoir.nodes.len),
3032 .extra_len = @intCast(zoir.extra.len),3038 .extra_len = @intCast(zoir.extra.len),
...@@ -3050,7 +3056,7 @@ pub fn saveZoirCache(cache_file: Io.File, stat: Io.File.Stat, zoir: Zoir) Io.Fil...@@ -3050,7 +3056,7 @@ pub fn saveZoirCache(cache_file: Io.File, stat: Io.File.Stat, zoir: Zoir) Io.Fil
3050 @ptrCast(zoir.compile_errors),3056 @ptrCast(zoir.compile_errors),
3051 @ptrCast(zoir.error_notes),3057 @ptrCast(zoir.error_notes),
3052 };3058 };
3053 var cache_fw = cache_file.writer(&.{});3059 var cache_fw = cache_file.writer(io, &.{});
3054 cache_fw.interface.writeVecAll(&vecs) catch |err| switch (err) {3060 cache_fw.interface.writeVecAll(&vecs) catch |err| switch (err) {
3055 error.WriteFailed => return cache_fw.err.?,3061 error.WriteFailed => return cache_fw.err.?,
3056 };3062 };
src/Zcu/PerThread.zig+6-6
...@@ -278,18 +278,18 @@ pub fn updateFile(...@@ -278,18 +278,18 @@ pub fn updateFile(
278 switch (file.getMode()) {278 switch (file.getMode()) {
279 .zig => {279 .zig => {
280 file.zir = try AstGen.generate(gpa, file.tree.?);280 file.zir = try AstGen.generate(gpa, file.tree.?);
281 Zcu.saveZirCache(gpa, cache_file, stat, file.zir.?) catch |err| switch (err) {281 Zcu.saveZirCache(gpa, io, cache_file, stat, file.zir.?) catch |err| switch (err) {
282 error.OutOfMemory => |e| return e,282 error.OutOfMemory => |e| return e,
283 else => log.warn("unable to write cached ZIR code for {f} to {f}{s}: {s}", .{283 else => log.warn("unable to write cached ZIR code for {f} to {f}{s}: {t}", .{
284 file.path.fmt(comp), cache_directory, &hex_digest, @errorName(err),284 file.path.fmt(comp), cache_directory, &hex_digest, err,
285 }),285 }),
286 };286 };
287 },287 },
288 .zon => {288 .zon => {
289 file.zoir = try ZonGen.generate(gpa, file.tree.?, .{});289 file.zoir = try ZonGen.generate(gpa, file.tree.?, .{});
290 Zcu.saveZoirCache(cache_file, stat, file.zoir.?) catch |err| {290 Zcu.saveZoirCache(io, cache_file, stat, file.zoir.?) catch |err| {
291 log.warn("unable to write cached ZOIR code for {f} to {f}{s}: {s}", .{291 log.warn("unable to write cached ZOIR code for {f} to {f}{s}: {t}", .{
292 file.path.fmt(comp), cache_directory, &hex_digest, @errorName(err),292 file.path.fmt(comp), cache_directory, &hex_digest, err,
293 });293 });
294 };294 };
295 },295 },
src/libs/mingw.zig+1-1
...@@ -380,7 +380,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -380,7 +380,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
380 const lib_final_file = try o_dir.createFile(io, final_lib_basename, .{ .truncate = true });380 const lib_final_file = try o_dir.createFile(io, final_lib_basename, .{ .truncate = true });
381 defer lib_final_file.close(io);381 defer lib_final_file.close(io);
382 var buffer: [1024]u8 = undefined;382 var buffer: [1024]u8 = undefined;
383 var file_writer = lib_final_file.writer(&buffer);383 var file_writer = lib_final_file.writer(io, &buffer);
384 try implib.writeCoffArchive(gpa, &file_writer.interface, members);384 try implib.writeCoffArchive(gpa, &file_writer.interface, members);
385 try file_writer.interface.flush();385 try file_writer.interface.flush();
386 }386 }
src/link.zig+1-1
...@@ -621,7 +621,7 @@ pub const File = struct {...@@ -621,7 +621,7 @@ pub const File = struct {
621 });621 });
622 defer gpa.free(tmp_sub_path);622 defer gpa.free(tmp_sub_path);
623 try emit.root_dir.handle.copyFile(emit.sub_path, emit.root_dir.handle, tmp_sub_path, .{});623 try emit.root_dir.handle.copyFile(emit.sub_path, emit.root_dir.handle, tmp_sub_path, .{});
624 try emit.root_dir.handle.rename(tmp_sub_path, emit.sub_path);624 try emit.root_dir.handle.rename(tmp_sub_path, emit.root_dir.handle, emit.sub_path, io);
625 switch (builtin.os.tag) {625 switch (builtin.os.tag) {
626 .linux => std.posix.ptrace(std.os.linux.PTRACE.ATTACH, pid, 0, 0) catch |err| {626 .linux => std.posix.ptrace(std.os.linux.PTRACE.ATTACH, pid, 0, 0) catch |err| {
627 log.warn("ptrace failure: {s}", .{@errorName(err)});627 log.warn("ptrace failure: {s}", .{@errorName(err)});
src/link/Lld.zig+1-1
...@@ -1631,7 +1631,7 @@ fn spawnLld(comp: *Compilation, arena: Allocator, argv: []const []const u8) !voi...@@ -1631,7 +1631,7 @@ fn spawnLld(comp: *Compilation, arena: Allocator, argv: []const []const u8) !voi
1631 {1631 {
1632 defer rsp_file.close(io);1632 defer rsp_file.close(io);
1633 var rsp_file_buffer: [1024]u8 = undefined;1633 var rsp_file_buffer: [1024]u8 = undefined;
1634 var rsp_file_writer = rsp_file.writer(&rsp_file_buffer);1634 var rsp_file_writer = rsp_file.writer(io, &rsp_file_buffer);
1635 const rsp_writer = &rsp_file_writer.interface;1635 const rsp_writer = &rsp_file_writer.interface;
1636 for (argv[2..]) |arg| {1636 for (argv[2..]) |arg| {
1637 try rsp_writer.writeByte('"');1637 try rsp_writer.writeByte('"');
src/main.zig+2-6
...@@ -3412,7 +3412,7 @@ fn buildOutputType(...@@ -3412,7 +3412,7 @@ fn buildOutputType(
3412 const sub_path = try std.fmt.allocPrint(arena, "tmp" ++ sep ++ "{x}-stdin{s}", .{3412 const sub_path = try std.fmt.allocPrint(arena, "tmp" ++ sep ++ "{x}-stdin{s}", .{
3413 &bin_digest, ext.canonicalName(target),3413 &bin_digest, ext.canonicalName(target),
3414 });3414 });
3415 try dirs.local_cache.handle.rename(dump_path, sub_path);3415 try dirs.local_cache.handle.rename(dump_path, dirs.local_cache.handle, sub_path, io);
34163416
3417 // Convert `sub_path` to be relative to current working directory.3417 // Convert `sub_path` to be relative to current working directory.
3418 src.src_path = try dirs.local_cache.join(arena, &.{sub_path});3418 src.src_path = try dirs.local_cache.join(arena, &.{sub_path});
...@@ -7216,11 +7216,7 @@ fn createDependenciesModule(...@@ -7216,11 +7216,7 @@ fn createDependenciesModule(
7216 const hex_digest = hh.final();7216 const hex_digest = hh.final();
72177217
7218 const o_dir_sub_path = try arena.dupe(u8, "o" ++ fs.path.sep_str ++ hex_digest);7218 const o_dir_sub_path = try arena.dupe(u8, "o" ++ fs.path.sep_str ++ hex_digest);
7219 try Package.Fetch.renameTmpIntoCache(7219 try Package.Fetch.renameTmpIntoCache(io, dirs.local_cache.handle, tmp_dir_sub_path, o_dir_sub_path);
7220 dirs.local_cache.handle,
7221 tmp_dir_sub_path,
7222 o_dir_sub_path,
7223 );
72247220
7225 const deps_mod = try Package.Module.create(arena, .{7221 const deps_mod = try Package.Module.create(arena, .{
7226 .paths = .{7222 .paths = .{