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 {
478478 validateSystemLibraryOptions(builder);
479479
480480 if (help_menu) {
481 var w = initStdoutWriter();
481 var w = initStdoutWriter(io);
482482 printUsage(builder, w) catch return stdout_writer_allocation.err.?;
483483 w.flush() catch return stdout_writer_allocation.err.?;
484484 return;
485485 }
486486
487487 if (steps_menu) {
488 var w = initStdoutWriter();
488 var w = initStdoutWriter(io);
489489 printSteps(builder, w) catch return stdout_writer_allocation.err.?;
490490 w.flush() catch return stdout_writer_allocation.err.?;
491491 return;
......@@ -1847,7 +1847,7 @@ fn createModuleDependenciesForStep(step: *Step) Allocator.Error!void {
18471847var stdio_buffer_allocation: [256]u8 = undefined;
18481848var stdout_writer_allocation: Io.File.Writer = undefined;
18491849
1850fn initStdoutWriter() *Writer {
1851 stdout_writer_allocation = Io.File.stdout().writerStreaming(&stdio_buffer_allocation);
1850fn initStdoutWriter(io: Io) *Writer {
1851 stdout_writer_allocation = Io.File.stdout().writerStreaming(io, &stdio_buffer_allocation);
18521852 return &stdout_writer_allocation.interface;
18531853}
lib/compiler/objcopy.zig+1-1
......@@ -183,7 +183,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
183183 var output_file = try Io.Dir.cwd().createFile(io, output, .{ .mode = mode });
184184 defer output_file.close(io);
185185
186 var out = output_file.writer(&output_buffer);
186 var out = output_file.writer(io, &output_buffer);
187187
188188 switch (out_fmt) {
189189 .hex, .raw => {
lib/std/Build/Cache.zig+2-2
......@@ -1134,13 +1134,13 @@ pub const Manifest = struct {
11341134 /// lock from exclusive to shared.
11351135 pub fn writeManifest(self: *Manifest) !void {
11361136 assert(self.have_exclusive_lock);
1137
1137 const io = self.cache.io;
11381138 const manifest_file = self.manifest_file.?;
11391139 if (self.manifest_dirty) {
11401140 self.manifest_dirty = false;
11411141
11421142 var buffer: [4000]u8 = undefined;
1143 var fw = manifest_file.writer(&buffer);
1143 var fw = manifest_file.writer(io, &buffer);
11441144 writeDirtyManifestToStream(self, &fw) catch |err| switch (err) {
11451145 error.WriteFailed => return fw.err.?,
11461146 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
389389 const target = run_step.producer.?.rootModuleTarget();
390390 var debug_info = std.debug.Info.load(
391391 fuzz.gpa,
392 io,
392393 rebuilt_exe_path,
393394 &gop.value_ptr.coverage,
394395 target.ofmt,
lib/std/Build/Step/Compile.zig+3-3
......@@ -1709,7 +1709,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
17091709 defer b.cache_root.handle.deleteFile(io, tmp_path) catch {
17101710 // It's fine if the temporary file can't be cleaned up.
17111711 };
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) {
17131713 error.PathAlreadyExists => {
17141714 // The args file was created by another concurrent build process.
17151715 },
......@@ -1827,14 +1827,14 @@ pub fn doAtomicSymLinks(
18271827 // sym link for libfoo.so.1 to libfoo.so.1.2.3
18281828 const major_only_path = b.pathJoin(&.{ out_dir, filename_major_only });
18291829 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| {
18311831 return step.fail("unable to symlink {s} -> {s}: {s}", .{
18321832 major_only_path, out_basename, @errorName(err),
18331833 });
18341834 };
18351835 // sym link for libfoo.so to libfoo.so.1
18361836 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| {
18381838 return step.fail("Unable to symlink {s} -> {s}: {s}", .{
18391839 name_only_path, filename_major_only, @errorName(err),
18401840 });
lib/std/Build/Step/Options.zig+1-1
......@@ -498,7 +498,7 @@ fn make(step: *Step, make_options: Step.MakeOptions) !void {
498498 });
499499 };
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) {
502502 error.PathAlreadyExists => {
503503 // Other process beat us to it. Clean up the temp file.
504504 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 {
10421042 if (any_output) {
10431043 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| {
10461046 if (err == error.PathAlreadyExists) {
10471047 b.cache_root.handle.deleteTree(o_sub_path) catch |del_err| {
1048 return step.fail("unable to remove dir '{f}'{s}: {s}", .{
1049 b.cache_root,
1050 tmp_dir_path,
1051 @errorName(del_err),
1048 return step.fail("unable to remove dir '{f}'{s}: {t}", .{
1049 b.cache_root, tmp_dir_path, del_err,
10521050 });
10531051 };
1054 b.cache_root.handle.rename(tmp_dir_path, o_sub_path) catch |retry_err| {
1055 return step.fail("unable to rename dir '{f}{s}' to '{f}{s}': {s}", .{
1056 b.cache_root, tmp_dir_path,
1057 b.cache_root, o_sub_path,
1058 @errorName(retry_err),
1052 b.cache_root.handle.rename(tmp_dir_path, b.cache_root.handle, o_sub_path, io) catch |retry_err| {
1053 return step.fail("unable to rename dir '{f}{s}' to '{f}{s}': {t}", .{
1054 b.cache_root, tmp_dir_path, b.cache_root, o_sub_path, retry_err,
10591055 });
10601056 };
10611057 } else {
1062 return step.fail("unable to rename dir '{f}{s}' to '{f}{s}': {s}", .{
1063 b.cache_root, tmp_dir_path,
1064 b.cache_root, o_sub_path,
1065 @errorName(err),
1058 return step.fail("unable to rename dir '{f}{s}' to '{f}{s}': {t}", .{
1059 b.cache_root, tmp_dir_path, b.cache_root, o_sub_path, err,
10661060 });
10671061 }
10681062 };
lib/std/Build/WebServer.zig+3-3
......@@ -523,7 +523,7 @@ pub fn serveTarFile(ws: *WebServer, request: *http.Server.Request, paths: []cons
523523 if (cached_cwd_path == null) cached_cwd_path = try std.process.getCwdAlloc(gpa);
524524 break :cwd cached_cwd_path.?;
525525 };
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()));
527527 }
528528
529529 // intentionally not calling `archiver.finishPedantically`
......@@ -587,7 +587,7 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim
587587 });
588588 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, &.{
591591 .{ .tag = .update, .bytes_len = 0 },
592592 .{ .tag = .exit, .bytes_len = 0 },
593593 })));
......@@ -638,7 +638,7 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim
638638 child.stdin.?.close(io);
639639 child.stdin = null;
640640
641 switch (try child.wait()) {
641 switch (try child.wait(io)) {
642642 .Exited => |code| {
643643 if (code != 0) {
644644 log.err(
lib/std/Io.zig+1-1
......@@ -677,7 +677,7 @@ pub const VTable = struct {
677677 dirDeleteFile: *const fn (?*anyopaque, Dir, []const u8) Dir.DeleteFileError!void,
678678 dirDeleteDir: *const fn (?*anyopaque, Dir, []const u8) Dir.DeleteDirError!void,
679679 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,
681681 dirReadLink: *const fn (?*anyopaque, Dir, sub_path: []const u8, buffer: []u8) Dir.ReadLinkError!usize,
682682 dirSetOwner: *const fn (?*anyopaque, Dir, ?File.Uid, ?File.Gid) Dir.SetOwnerError!void,
683683 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;
501501pub fn writeFile(dir: Dir, io: Io, options: WriteFileOptions) WriteFileError!void {
502502 var file = try dir.createFile(io, options.sub_path, options.flags);
503503 defer file.close(io);
504 try file.writeAll(io, options.data);
504 try file.writeStreamingAll(io, options.data);
505505}
506506
507507pub const PrevStatus = enum {
......@@ -955,6 +955,13 @@ pub fn rename(
955955 return io.vtable.dirRename(io.userdata, old_dir, old_sub_path, new_dir, new_sub_path);
956956}
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
958965/// Use with `Dir.symLink`, `Dir.symLinkAtomic`, and `symLinkAbsolute` to
959966/// specify whether the symlink will point to a file or a directory. This value
960967/// is ignored on all hosts except Windows where creating symlinks to different
......@@ -1053,7 +1060,7 @@ pub fn symLinkAtomic(
10531060 temp_path[dirname.len + 1 ..][0..rand_len].* = std.fmt.hex(random_integer);
10541061
10551062 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);
10571064 } else |err| switch (err) {
10581065 error.PathAlreadyExists => continue,
10591066 else => |e| return e,
lib/std/fs/test.zig+19-19
......@@ -961,14 +961,14 @@ test "Dir.rename files" {
961961 const missing_file_path = try ctx.transformPath("missing_file_name");
962962 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
966966 // Renaming files
967967 const test_file_name = try ctx.transformPath("test_file");
968968 const renamed_test_file_name = try ctx.transformPath("test_file_renamed");
969969 var file = try ctx.dir.createFile(io, test_file_name, .{ .read = true });
970970 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
973973 // Ensure the file was renamed
974974 try testing.expectError(error.FileNotFound, ctx.dir.openFile(io, test_file_name, .{}));
......@@ -976,13 +976,13 @@ test "Dir.rename files" {
976976 file.close(io);
977977
978978 // 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
981981 // Rename to existing file succeeds
982982 const existing_file_path = try ctx.transformPath("existing_file");
983983 var existing_file = try ctx.dir.createFile(io, existing_file_path, .{ .read = true });
984984 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
987987 try testing.expectError(error.FileNotFound, ctx.dir.openFile(io, renamed_test_file_name, .{}));
988988 file = try ctx.dir.openFile(io, existing_file_path, .{});
......@@ -1007,7 +1007,7 @@ test "Dir.rename directories" {
10071007
10081008 // Renaming directories
10091009 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
10121012 // Ensure the directory was renamed
10131013 try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_path, .{}));
......@@ -1019,7 +1019,7 @@ test "Dir.rename directories" {
10191019 dir.close(io);
10201020
10211021 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
10241024 // Ensure the directory was renamed and the file still exists in it
10251025 try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_renamed_path, .{}));
......@@ -1044,7 +1044,7 @@ test "Dir.rename directory onto empty dir" {
10441044
10451045 try ctx.dir.makeDir(test_dir_path);
10461046 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
10491049 // Ensure the directory was renamed
10501050 try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_path, .{}));
......@@ -1072,7 +1072,7 @@ test "Dir.rename directory onto non-empty dir" {
10721072 target_dir.close(io);
10731073
10741074 // 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
10771077 // Ensure the directory was not renamed
10781078 var dir = try ctx.dir.openDir(io, test_dir_path, .{});
......@@ -1094,8 +1094,8 @@ test "Dir.rename file <-> dir" {
10941094 var file = try ctx.dir.createFile(io, test_file_path, .{ .read = true });
10951095 file.close(io);
10961096 try ctx.dir.makeDir(test_dir_path);
1097 try testing.expectError(error.IsDir, ctx.dir.rename(test_file_path, test_dir_path));
1098 try testing.expectError(error.NotDir, ctx.dir.rename(test_dir_path, test_file_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, ctx.dir, test_file_path, io));
10991099 }
11001100 }.impl);
11011101}
......@@ -1114,7 +1114,7 @@ test "rename" {
11141114 const renamed_test_file_name = "test_file_renamed";
11151115 var file = try tmp_dir1.dir.createFile(io, test_file_name, .{ .read = true });
11161116 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
11191119 // ensure the file was renamed
11201120 try testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(io, test_file_name, .{}));
......@@ -1492,7 +1492,7 @@ test "pwritev, preadv" {
14921492 var src_file = try tmp.dir.createFile(io, "test.txt", .{ .read = true });
14931493 defer src_file.close(io);
14941494
1495 var writer = src_file.writer(&.{});
1495 var writer = src_file.writer(io, &.{});
14961496
14971497 try writer.seekTo(16);
14981498 try writer.interface.writeVecAll(&lines);
......@@ -1593,7 +1593,7 @@ test "sendfile" {
15931593 var src_file = try dir.createFile(io, "sendfile1.txt", .{ .read = true });
15941594 defer src_file.close(io);
15951595 {
1596 var fw = src_file.writer(&.{});
1596 var fw = src_file.writer(io, &.{});
15971597 try fw.interface.writeVecAll(&vecs);
15981598 }
15991599
......@@ -1610,7 +1610,7 @@ test "sendfile" {
16101610 var written_buf: [100]u8 = undefined;
16111611 var file_reader = src_file.reader(io, &.{});
16121612 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);
16141614 try file_writer.interface.writeVecAll(&headers);
16151615 try file_reader.seekTo(1);
16161616 try testing.expectEqual(10, try file_writer.interface.sendFileAll(&file_reader, .limited(10)));
......@@ -1648,7 +1648,7 @@ test "sendfile with buffered data" {
16481648 try file_reader.interface.fill(8);
16491649
16501650 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
16531653 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" {
20512051 try ctx.dir.access(io, file_path, .{});
20522052
20532053 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);
20552055 const renamed_file = try ctx.dir.openFile(io, rename_path, .{});
20562056 renamed_file.close(io);
20572057 try ctx.dir.deleteFile(rename_path);
......@@ -2175,7 +2175,7 @@ test "invalid UTF-8/WTF-8 paths" {
21752175
21762176 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
21802180 try testing.expectError(expected_err, ctx.dir.symLink(invalid_path, invalid_path, .{}));
21812181 if (native_os == .wasi) {
......@@ -2208,7 +2208,7 @@ test "invalid UTF-8/WTF-8 paths" {
22082208 try testing.expectError(expected_err, ctx.dir.realpathAlloc(testing.allocator, invalid_path));
22092209 }
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
22132213 if (native_os != .wasi and ctx.path_type != .relative) {
22142214 try testing.expectError(expected_err, Dir.copyFileAbsolute(invalid_path, invalid_path, .{}));
......@@ -2334,7 +2334,7 @@ test "seekTo flushes buffered data" {
23342334 defer file.close(io);
23352335 {
23362336 var buf: [16]u8 = undefined;
2337 var file_writer = File.writer(file, &buf);
2337 var file_writer = file.writer(io, file, &buf);
23382338
23392339 try file_writer.interface.writeAll(contents);
23402340 try file_writer.seekTo(8);
lib/std/posix/test.zig+2-2
......@@ -690,7 +690,7 @@ test "rename smoke test" {
690690 // Rename the file
691691 const new_file_path = try fs.path.join(a, &.{ base_path, "some_other_file" });
692692 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);
694694 }
695695
696696 {
......@@ -717,7 +717,7 @@ test "rename smoke test" {
717717 // Rename the directory
718718 const new_file_path = try fs.path.join(a, &.{ base_path, "some_other_dir" });
719719 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);
721721 }
722722
723723 {
lib/std/tar.zig+1-1
......@@ -612,7 +612,7 @@ pub fn pipeToFileSystem(io: Io, dir: Io.Dir, reader: *Io.Reader, options: PipeOp
612612 .file => {
613613 if (createDirAndFile(io, dir, file_name, fileMode(file.mode, options))) |fs_file| {
614614 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);
616616 try it.streamRemaining(file, &file_writer.interface);
617617 try file_writer.interface.flush();
618618 } else |err| {
lib/std/zip.zig+1-1
......@@ -570,7 +570,7 @@ pub const Iterator = struct {
570570 };
571571 defer out_file.close(io);
572572 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);
574574 const local_data_file_offset: u64 =
575575 @as(u64, self.file_offset) +
576576 @as(u64, @sizeOf(LocalFileHeader)) +
src/Compilation.zig+3-3
......@@ -5303,7 +5303,7 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {
53035303 defer tar_file.close(io);
53045304
53055305 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
53085308 var seen_table: std.AutoArrayHashMapUnmanaged(*Package.Module, []const u8) = .empty;
53095309 defer seen_table.deinit(comp.gpa);
......@@ -6448,7 +6448,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
64486448 var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(o_sub_path, .{});
64496449 defer o_dir.close(io);
64506450 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);
64526452 break :blk digest;
64536453 };
64546454
......@@ -6696,7 +6696,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
66966696 var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(o_sub_path, .{});
66976697 defer o_dir.close(io);
66986698 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);
67006700 break :blk digest;
67016701 };
67026702
src/Package/Fetch.zig+6-6
......@@ -567,7 +567,7 @@ fn runResource(
567567 .root_dir = cache_root,
568568 .sub_path = try std.fmt.allocPrint(arena, "p" ++ s ++ "{s}", .{computed_package_hash.toSlice()}),
569569 };
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| {
571571 const src = try cache_root.join(arena, &.{tmp_dir_sub_path});
572572 const dest = try cache_root.join(arena, &.{f.package_root.sub_path});
573573 try eb.addRootErrorMessage(.{ .msg = try eb.printString(
......@@ -1319,7 +1319,7 @@ fn unzip(
13191319 defer zip_file.close(io);
13201320 var zip_file_buffer: [4096]u8 = undefined;
13211321 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
13241324 _ = reader.streamRemaining(&zip_file_writer.interface) catch |err| switch (err) {
13251325 error.ReadFailed => return error.ReadFailed,
......@@ -1370,7 +1370,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
13701370 defer pack_file.close(io);
13711371 var pack_file_buffer: [4096]u8 = undefined;
13721372 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);
13741374 const fetch_reader = &resource.fetch_stream.reader;
13751375 _ = try fetch_reader.streamRemaining(&pack_file_writer.interface);
13761376 try pack_file_writer.interface.flush();
......@@ -1380,7 +1380,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
13801380 var index_file = try pack_dir.createFile(io, "pkg.idx", .{ .read = true });
13811381 defer index_file.close(io);
13821382 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);
13841384 {
13851385 const index_prog_node = f.prog_node.start("Index pack", 0);
13861386 defer index_prog_node.end();
......@@ -1454,11 +1454,11 @@ fn recursiveDirectoryCopy(f: *Fetch, dir: Io.Dir, tmp_dir: Io.Dir) anyerror!void
14541454 }
14551455}
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 {
14581458 assert(dest_dir_sub_path[1] == fs.path.sep);
14591459 var handled_missing_dir = false;
14601460 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) {
14621462 error.FileNotFound => {
14631463 if (handled_missing_dir) return err;
14641464 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
15941594 var index_file = try git_dir.dir.createFile(io, "testrepo.idx", .{ .read = true });
15951595 defer index_file.close(io);
15961596 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);
15981598 try indexPack(testing.allocator, format, &pack_file_reader, &index_file_writer);
15991599
16001600 // Arbitrary size limit on files read while checking the repository contents
......@@ -1730,7 +1730,7 @@ pub fn main() !void {
17301730 var index_file = try git_dir.createFile(io, "idx", .{ .read = true });
17311731 defer index_file.close(io);
17321732 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);
17341734 try indexPack(allocator, format, &pack_file_reader, &index_file_writer);
17351735
17361736 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
29862986 return zir;
29872987}
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 {
29902996 const safety_buffer = if (data_has_safety_tag)
29912997 try gpa.alloc([8]u8, zir.instructions.len)
29922998 else
......@@ -3020,13 +3026,13 @@ pub fn saveZirCache(gpa: Allocator, cache_file: Io.File, stat: Io.File.Stat, zir
30203026 zir.string_bytes,
30213027 @ptrCast(zir.extra),
30223028 };
3023 var cache_fw = cache_file.writer(&.{});
3029 var cache_fw = cache_file.writer(io, &.{});
30243030 cache_fw.interface.writeVecAll(&vecs) catch |err| switch (err) {
30253031 error.WriteFailed => return cache_fw.err.?,
30263032 };
30273033}
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 {
30303036 const header: Zoir.Header = .{
30313037 .nodes_len = @intCast(zoir.nodes.len),
30323038 .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
30503056 @ptrCast(zoir.compile_errors),
30513057 @ptrCast(zoir.error_notes),
30523058 };
3053 var cache_fw = cache_file.writer(&.{});
3059 var cache_fw = cache_file.writer(io, &.{});
30543060 cache_fw.interface.writeVecAll(&vecs) catch |err| switch (err) {
30553061 error.WriteFailed => return cache_fw.err.?,
30563062 };
src/Zcu/PerThread.zig+6-6
......@@ -278,18 +278,18 @@ pub fn updateFile(
278278 switch (file.getMode()) {
279279 .zig => {
280280 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) {
282282 error.OutOfMemory => |e| return e,
283 else => log.warn("unable to write cached ZIR code for {f} to {f}{s}: {s}", .{
284 file.path.fmt(comp), cache_directory, &hex_digest, @errorName(err),
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, err,
285285 }),
286286 };
287287 },
288288 .zon => {
289289 file.zoir = try ZonGen.generate(gpa, file.tree.?, .{});
290 Zcu.saveZoirCache(cache_file, stat, file.zoir.?) catch |err| {
291 log.warn("unable to write cached ZOIR code for {f} to {f}{s}: {s}", .{
292 file.path.fmt(comp), cache_directory, &hex_digest, @errorName(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}: {t}", .{
292 file.path.fmt(comp), cache_directory, &hex_digest, err,
293293 });
294294 };
295295 },
src/libs/mingw.zig+1-1
......@@ -380,7 +380,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
380380 const lib_final_file = try o_dir.createFile(io, final_lib_basename, .{ .truncate = true });
381381 defer lib_final_file.close(io);
382382 var buffer: [1024]u8 = undefined;
383 var file_writer = lib_final_file.writer(&buffer);
383 var file_writer = lib_final_file.writer(io, &buffer);
384384 try implib.writeCoffArchive(gpa, &file_writer.interface, members);
385385 try file_writer.interface.flush();
386386 }
src/link.zig+1-1
......@@ -621,7 +621,7 @@ pub const File = struct {
621621 });
622622 defer gpa.free(tmp_sub_path);
623623 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);
625625 switch (builtin.os.tag) {
626626 .linux => std.posix.ptrace(std.os.linux.PTRACE.ATTACH, pid, 0, 0) catch |err| {
627627 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
16311631 {
16321632 defer rsp_file.close(io);
16331633 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);
16351635 const rsp_writer = &rsp_file_writer.interface;
16361636 for (argv[2..]) |arg| {
16371637 try rsp_writer.writeByte('"');
src/main.zig+2-6
......@@ -3412,7 +3412,7 @@ fn buildOutputType(
34123412 const sub_path = try std.fmt.allocPrint(arena, "tmp" ++ sep ++ "{x}-stdin{s}", .{
34133413 &bin_digest, ext.canonicalName(target),
34143414 });
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
34173417 // Convert `sub_path` to be relative to current working directory.
34183418 src.src_path = try dirs.local_cache.join(arena, &.{sub_path});
......@@ -7216,11 +7216,7 @@ fn createDependenciesModule(
72167216 const hex_digest = hh.final();
72177217
72187218 const o_dir_sub_path = try arena.dupe(u8, "o" ++ fs.path.sep_str ++ hex_digest);
7219 try Package.Fetch.renameTmpIntoCache(
7220 dirs.local_cache.handle,
7221 tmp_dir_sub_path,
7222 o_dir_sub_path,
7223 );
7219 try Package.Fetch.renameTmpIntoCache(io, dirs.local_cache.handle, tmp_dir_sub_path, o_dir_sub_path);
72247220
72257221 const deps_mod = try Package.Module.create(arena, .{
72267222 .paths = .{