aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-12-08 17:45:17 -0800
committerAndrew Kelley <andrew@ziglang.org>2025-12-23 22:15:08 -0800
commit4be8be1d2bd6959efae7df95e3f5713adf953a42 (patch)
treeee9fb0f267e80ba20d4ae26e1ee61c5c348a08da /lib/std
parent4218344dd3178f2fd3d9d00e9ff6895ee344df6d (diff)
downloadzig-4be8be1d2bd6959efae7df95e3f5713adf953a42.tar.gz
zig-4be8be1d2bd6959efae7df95e3f5713adf953a42.zip
update all rename() to rename(io)
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/Build/Cache.zig4
-rw-r--r--lib/std/Build/Fuzz.zig1
-rw-r--r--lib/std/Build/Step/Compile.zig6
-rw-r--r--lib/std/Build/Step/Options.zig2
-rw-r--r--lib/std/Build/Step/Run.zig22
-rw-r--r--lib/std/Build/WebServer.zig6
-rw-r--r--lib/std/Io.zig2
-rw-r--r--lib/std/Io/Dir.zig11
-rw-r--r--lib/std/fs/test.zig38
-rw-r--r--lib/std/posix/test.zig4
-rw-r--r--lib/std/tar.zig2
-rw-r--r--lib/std/zip.zig2
12 files changed, 51 insertions, 49 deletions
diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig
index f7c4d729bc..2d6dbc02fa 100644
--- a/lib/std/Build/Cache.zig
+++ b/lib/std/Build/Cache.zig
@@ -1134,13 +1134,13 @@ pub const Manifest = struct {
/// lock from exclusive to shared.
pub fn writeManifest(self: *Manifest) !void {
assert(self.have_exclusive_lock);
-
+ const io = self.cache.io;
const manifest_file = self.manifest_file.?;
if (self.manifest_dirty) {
self.manifest_dirty = false;
var buffer: [4000]u8 = undefined;
- var fw = manifest_file.writer(&buffer);
+ var fw = manifest_file.writer(io, &buffer);
writeDirtyManifestToStream(self, &fw) catch |err| switch (err) {
error.WriteFailed => return fw.err.?,
else => |e| return e,
diff --git a/lib/std/Build/Fuzz.zig b/lib/std/Build/Fuzz.zig
index 8d5bc27f3a..8fedb7e067 100644
--- a/lib/std/Build/Fuzz.zig
+++ b/lib/std/Build/Fuzz.zig
@@ -389,6 +389,7 @@ fn prepareTables(fuzz: *Fuzz, run_step: *Step.Run, coverage_id: u64) error{ OutO
const target = run_step.producer.?.rootModuleTarget();
var debug_info = std.debug.Info.load(
fuzz.gpa,
+ io,
rebuilt_exe_path,
&gop.value_ptr.coverage,
target.ofmt,
diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig
index 4f1e83a573..dfa5460981 100644
--- a/lib/std/Build/Step/Compile.zig
+++ b/lib/std/Build/Step/Compile.zig
@@ -1709,7 +1709,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
defer b.cache_root.handle.deleteFile(io, tmp_path) catch {
// It's fine if the temporary file can't be cleaned up.
};
- b.cache_root.handle.rename(io, tmp_path, args_file) catch |rename_err| switch (rename_err) {
+ b.cache_root.handle.rename(tmp_path, b.cache_root.handle, args_file, io) catch |rename_err| switch (rename_err) {
error.PathAlreadyExists => {
// The args file was created by another concurrent build process.
},
@@ -1827,14 +1827,14 @@ pub fn doAtomicSymLinks(
// sym link for libfoo.so.1 to libfoo.so.1.2.3
const major_only_path = b.pathJoin(&.{ out_dir, filename_major_only });
const cwd: Io.Dir = .cwd();
- cwd.atomicSymLink(io, out_basename, major_only_path, .{}) catch |err| {
+ cwd.symLinkAtomic(io, out_basename, major_only_path, .{}) catch |err| {
return step.fail("unable to symlink {s} -> {s}: {s}", .{
major_only_path, out_basename, @errorName(err),
});
};
// sym link for libfoo.so to libfoo.so.1
const name_only_path = b.pathJoin(&.{ out_dir, filename_name_only });
- cwd.atomicSymLink(io, filename_major_only, name_only_path, .{}) catch |err| {
+ cwd.symLinkAtomic(io, filename_major_only, name_only_path, .{}) catch |err| {
return step.fail("Unable to symlink {s} -> {s}: {s}", .{
name_only_path, filename_major_only, @errorName(err),
});
diff --git a/lib/std/Build/Step/Options.zig b/lib/std/Build/Step/Options.zig
index 1416e0e916..676ea4d851 100644
--- a/lib/std/Build/Step/Options.zig
+++ b/lib/std/Build/Step/Options.zig
@@ -498,7 +498,7 @@ fn make(step: *Step, make_options: Step.MakeOptions) !void {
});
};
- b.cache_root.handle.rename(io, tmp_sub_path, sub_path) catch |err| switch (err) {
+ b.cache_root.handle.rename(tmp_sub_path, b.cache_root.handle, sub_path, io) catch |err| switch (err) {
error.PathAlreadyExists => {
// Other process beat us to it. Clean up the temp file.
b.cache_root.handle.deleteFile(io, tmp_sub_path) catch |e| {
diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig
index a1618beb02..e52dd21a96 100644
--- a/lib/std/Build/Step/Run.zig
+++ b/lib/std/Build/Step/Run.zig
@@ -1042,27 +1042,21 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
if (any_output) {
const o_sub_path = "o" ++ fs.path.sep_str ++ &digest;
- b.cache_root.handle.rename(tmp_dir_path, o_sub_path) catch |err| {
+ b.cache_root.handle.rename(tmp_dir_path, b.cache_root.handle, o_sub_path, io) catch |err| {
if (err == error.PathAlreadyExists) {
b.cache_root.handle.deleteTree(o_sub_path) catch |del_err| {
- return step.fail("unable to remove dir '{f}'{s}: {s}", .{
- b.cache_root,
- tmp_dir_path,
- @errorName(del_err),
+ return step.fail("unable to remove dir '{f}'{s}: {t}", .{
+ b.cache_root, tmp_dir_path, del_err,
});
};
- b.cache_root.handle.rename(tmp_dir_path, o_sub_path) catch |retry_err| {
- return step.fail("unable to rename dir '{f}{s}' to '{f}{s}': {s}", .{
- b.cache_root, tmp_dir_path,
- b.cache_root, o_sub_path,
- @errorName(retry_err),
+ b.cache_root.handle.rename(tmp_dir_path, b.cache_root.handle, o_sub_path, io) catch |retry_err| {
+ return step.fail("unable to rename dir '{f}{s}' to '{f}{s}': {t}", .{
+ b.cache_root, tmp_dir_path, b.cache_root, o_sub_path, retry_err,
});
};
} else {
- return step.fail("unable to rename dir '{f}{s}' to '{f}{s}': {s}", .{
- b.cache_root, tmp_dir_path,
- b.cache_root, o_sub_path,
- @errorName(err),
+ return step.fail("unable to rename dir '{f}{s}' to '{f}{s}': {t}", .{
+ b.cache_root, tmp_dir_path, b.cache_root, o_sub_path, err,
});
}
};
diff --git a/lib/std/Build/WebServer.zig b/lib/std/Build/WebServer.zig
index ed07d04d57..38a7a73588 100644
--- a/lib/std/Build/WebServer.zig
+++ b/lib/std/Build/WebServer.zig
@@ -523,7 +523,7 @@ pub fn serveTarFile(ws: *WebServer, request: *http.Server.Request, paths: []cons
if (cached_cwd_path == null) cached_cwd_path = try std.process.getCwdAlloc(gpa);
break :cwd cached_cwd_path.?;
};
- try archiver.writeFile(io, path.sub_path, &file_reader, @intCast(stat.mtime.toSeconds()));
+ try archiver.writeFile(path.sub_path, &file_reader, @intCast(stat.mtime.toSeconds()));
}
// intentionally not calling `archiver.finishPedantically`
@@ -587,7 +587,7 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim
});
defer poller.deinit();
- try child.stdin.?.writeAll(@ptrCast(@as([]const std.zig.Client.Message.Header, &.{
+ try child.stdin.?.writeStreamingAll(io, @ptrCast(@as([]const std.zig.Client.Message.Header, &.{
.{ .tag = .update, .bytes_len = 0 },
.{ .tag = .exit, .bytes_len = 0 },
})));
@@ -638,7 +638,7 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim
child.stdin.?.close(io);
child.stdin = null;
- switch (try child.wait()) {
+ switch (try child.wait(io)) {
.Exited => |code| {
if (code != 0) {
log.err(
diff --git a/lib/std/Io.zig b/lib/std/Io.zig
index 7f5f049d34..193998f037 100644
--- a/lib/std/Io.zig
+++ b/lib/std/Io.zig
@@ -677,7 +677,7 @@ pub const VTable = struct {
dirDeleteFile: *const fn (?*anyopaque, Dir, []const u8) Dir.DeleteFileError!void,
dirDeleteDir: *const fn (?*anyopaque, Dir, []const u8) Dir.DeleteDirError!void,
dirRename: *const fn (?*anyopaque, old_dir: Dir, old_sub_path: []const u8, new_dir: Dir, new_sub_path: []const u8) Dir.RenameError!void,
- dirSymLink: *const fn (?*anyopaque, Dir, target_path: []const u8, sym_link_path: []const u8, Dir.SymLinkFlags) Dir.RenameError!void,
+ dirSymLink: *const fn (?*anyopaque, Dir, target_path: []const u8, sym_link_path: []const u8, Dir.SymLinkFlags) Dir.SymLinkError!void,
dirReadLink: *const fn (?*anyopaque, Dir, sub_path: []const u8, buffer: []u8) Dir.ReadLinkError!usize,
dirSetOwner: *const fn (?*anyopaque, Dir, ?File.Uid, ?File.Gid) Dir.SetOwnerError!void,
dirSetPermissions: *const fn (?*anyopaque, Dir, Dir.Permissions) Dir.SetPermissionsError!void,
diff --git a/lib/std/Io/Dir.zig b/lib/std/Io/Dir.zig
index 755ce924ad..7d1f6212dc 100644
--- a/lib/std/Io/Dir.zig
+++ b/lib/std/Io/Dir.zig
@@ -501,7 +501,7 @@ pub const WriteFileError = File.Writer.Error || File.OpenError;
pub fn writeFile(dir: Dir, io: Io, options: WriteFileOptions) WriteFileError!void {
var file = try dir.createFile(io, options.sub_path, options.flags);
defer file.close(io);
- try file.writeAll(io, options.data);
+ try file.writeStreamingAll(io, options.data);
}
pub const PrevStatus = enum {
@@ -955,6 +955,13 @@ pub fn rename(
return io.vtable.dirRename(io.userdata, old_dir, old_sub_path, new_dir, new_sub_path);
}
+pub fn renameAbsolute(io: Io, old_path: []const u8, new_path: []const u8) RenameError!void {
+ assert(path.isAbsolute(old_path));
+ assert(path.isAbsolute(new_path));
+ const my_cwd = cwd();
+ return io.vtable.dirRename(io.userdata, my_cwd, old_path, my_cwd, new_path);
+}
+
/// Use with `Dir.symLink`, `Dir.symLinkAtomic`, and `symLinkAbsolute` to
/// specify whether the symlink will point to a file or a directory. This value
/// is ignored on all hosts except Windows where creating symlinks to different
@@ -1053,7 +1060,7 @@ pub fn symLinkAtomic(
temp_path[dirname.len + 1 ..][0..rand_len].* = std.fmt.hex(random_integer);
if (dir.symLink(io, target_path, temp_path, flags)) {
- return dir.rename(temp_path, dir, io, sym_link_path);
+ return dir.rename(temp_path, dir, sym_link_path, io);
} else |err| switch (err) {
error.PathAlreadyExists => continue,
else => |e| return e,
diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig
index 59e0990eb0..92992f91b4 100644
--- a/lib/std/fs/test.zig
+++ b/lib/std/fs/test.zig
@@ -961,14 +961,14 @@ test "Dir.rename files" {
const missing_file_path = try ctx.transformPath("missing_file_name");
const something_else_path = try ctx.transformPath("something_else");
- try testing.expectError(error.FileNotFound, ctx.dir.rename(missing_file_path, something_else_path));
+ try testing.expectError(error.FileNotFound, ctx.dir.rename(missing_file_path, ctx.dir, something_else_path, io));
// Renaming files
const test_file_name = try ctx.transformPath("test_file");
const renamed_test_file_name = try ctx.transformPath("test_file_renamed");
var file = try ctx.dir.createFile(io, test_file_name, .{ .read = true });
file.close(io);
- try ctx.dir.rename(test_file_name, renamed_test_file_name);
+ try ctx.dir.rename(test_file_name, ctx.dir, renamed_test_file_name, io);
// Ensure the file was renamed
try testing.expectError(error.FileNotFound, ctx.dir.openFile(io, test_file_name, .{}));
@@ -976,13 +976,13 @@ test "Dir.rename files" {
file.close(io);
// Rename to self succeeds
- try ctx.dir.rename(renamed_test_file_name, renamed_test_file_name);
+ try ctx.dir.rename(renamed_test_file_name, ctx.dir, renamed_test_file_name, io);
// Rename to existing file succeeds
const existing_file_path = try ctx.transformPath("existing_file");
var existing_file = try ctx.dir.createFile(io, existing_file_path, .{ .read = true });
existing_file.close(io);
- try ctx.dir.rename(renamed_test_file_name, existing_file_path);
+ try ctx.dir.rename(renamed_test_file_name, ctx.dir, existing_file_path, io);
try testing.expectError(error.FileNotFound, ctx.dir.openFile(io, renamed_test_file_name, .{}));
file = try ctx.dir.openFile(io, existing_file_path, .{});
@@ -1007,7 +1007,7 @@ test "Dir.rename directories" {
// Renaming directories
try ctx.dir.makeDir(test_dir_path);
- try ctx.dir.rename(test_dir_path, test_dir_renamed_path);
+ try ctx.dir.rename(test_dir_path, ctx.dir, test_dir_renamed_path, io);
// Ensure the directory was renamed
try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_path, .{}));
@@ -1019,7 +1019,7 @@ test "Dir.rename directories" {
dir.close(io);
const test_dir_renamed_again_path = try ctx.transformPath("test_dir_renamed_again");
- try ctx.dir.rename(test_dir_renamed_path, test_dir_renamed_again_path);
+ try ctx.dir.rename(test_dir_renamed_path, ctx.dir, test_dir_renamed_again_path, io);
// Ensure the directory was renamed and the file still exists in it
try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_renamed_path, .{}));
@@ -1044,7 +1044,7 @@ test "Dir.rename directory onto empty dir" {
try ctx.dir.makeDir(test_dir_path);
try ctx.dir.makeDir(target_dir_path);
- try ctx.dir.rename(test_dir_path, target_dir_path);
+ try ctx.dir.rename(test_dir_path, ctx.dir, target_dir_path, io);
// Ensure the directory was renamed
try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, test_dir_path, .{}));
@@ -1072,7 +1072,7 @@ test "Dir.rename directory onto non-empty dir" {
target_dir.close(io);
// Rename should fail with PathAlreadyExists if target_dir is non-empty
- try testing.expectError(error.PathAlreadyExists, ctx.dir.rename(test_dir_path, target_dir_path));
+ try testing.expectError(error.PathAlreadyExists, ctx.dir.rename(test_dir_path, ctx.dir, target_dir_path, io));
// Ensure the directory was not renamed
var dir = try ctx.dir.openDir(io, test_dir_path, .{});
@@ -1094,8 +1094,8 @@ test "Dir.rename file <-> dir" {
var file = try ctx.dir.createFile(io, test_file_path, .{ .read = true });
file.close(io);
try ctx.dir.makeDir(test_dir_path);
- try testing.expectError(error.IsDir, ctx.dir.rename(test_file_path, test_dir_path));
- try testing.expectError(error.NotDir, ctx.dir.rename(test_dir_path, test_file_path));
+ try testing.expectError(error.IsDir, ctx.dir.rename(test_file_path, ctx.dir, test_dir_path, io));
+ try testing.expectError(error.NotDir, ctx.dir.rename(test_dir_path, ctx.dir, test_file_path, io));
}
}.impl);
}
@@ -1114,7 +1114,7 @@ test "rename" {
const renamed_test_file_name = "test_file_renamed";
var file = try tmp_dir1.dir.createFile(io, test_file_name, .{ .read = true });
file.close(io);
- try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name);
+ try Dir.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name, io);
// ensure the file was renamed
try testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(io, test_file_name, .{}));
@@ -1492,7 +1492,7 @@ test "pwritev, preadv" {
var src_file = try tmp.dir.createFile(io, "test.txt", .{ .read = true });
defer src_file.close(io);
- var writer = src_file.writer(&.{});
+ var writer = src_file.writer(io, &.{});
try writer.seekTo(16);
try writer.interface.writeVecAll(&lines);
@@ -1593,7 +1593,7 @@ test "sendfile" {
var src_file = try dir.createFile(io, "sendfile1.txt", .{ .read = true });
defer src_file.close(io);
{
- var fw = src_file.writer(&.{});
+ var fw = src_file.writer(io, &.{});
try fw.interface.writeVecAll(&vecs);
}
@@ -1610,7 +1610,7 @@ test "sendfile" {
var written_buf: [100]u8 = undefined;
var file_reader = src_file.reader(io, &.{});
var fallback_buffer: [50]u8 = undefined;
- var file_writer = dest_file.writer(&fallback_buffer);
+ var file_writer = dest_file.writer(io, &fallback_buffer);
try file_writer.interface.writeVecAll(&headers);
try file_reader.seekTo(1);
try testing.expectEqual(10, try file_writer.interface.sendFileAll(&file_reader, .limited(10)));
@@ -1648,7 +1648,7 @@ test "sendfile with buffered data" {
try file_reader.interface.fill(8);
var fallback_buffer: [32]u8 = undefined;
- var file_writer = dest_file.writer(&fallback_buffer);
+ var file_writer = dest_file.writer(io, &fallback_buffer);
try std.testing.expectEqual(4, try file_writer.interface.sendFileAll(&file_reader, .limited(4)));
@@ -2051,7 +2051,7 @@ test "'.' and '..' in Io.Dir functions" {
try ctx.dir.access(io, file_path, .{});
try ctx.dir.copyFile(file_path, ctx.dir, copy_path, .{});
- try ctx.dir.rename(copy_path, rename_path);
+ try ctx.dir.rename(copy_path, ctx.dir, rename_path, io);
const renamed_file = try ctx.dir.openFile(io, rename_path, .{});
renamed_file.close(io);
try ctx.dir.deleteFile(rename_path);
@@ -2175,7 +2175,7 @@ test "invalid UTF-8/WTF-8 paths" {
try testing.expectError(expected_err, ctx.dir.deleteDir(invalid_path));
- try testing.expectError(expected_err, ctx.dir.rename(invalid_path, invalid_path));
+ try testing.expectError(expected_err, ctx.dir.rename(invalid_path, ctx.dir, invalid_path, io));
try testing.expectError(expected_err, ctx.dir.symLink(invalid_path, invalid_path, .{}));
if (native_os == .wasi) {
@@ -2208,7 +2208,7 @@ test "invalid UTF-8/WTF-8 paths" {
try testing.expectError(expected_err, ctx.dir.realpathAlloc(testing.allocator, invalid_path));
}
- try testing.expectError(expected_err, fs.rename(ctx.dir, invalid_path, ctx.dir, invalid_path));
+ try testing.expectError(expected_err, Dir.rename(ctx.dir, invalid_path, ctx.dir, invalid_path, io));
if (native_os != .wasi and ctx.path_type != .relative) {
try testing.expectError(expected_err, Dir.copyFileAbsolute(invalid_path, invalid_path, .{}));
@@ -2334,7 +2334,7 @@ test "seekTo flushes buffered data" {
defer file.close(io);
{
var buf: [16]u8 = undefined;
- var file_writer = File.writer(file, &buf);
+ var file_writer = file.writer(io, file, &buf);
try file_writer.interface.writeAll(contents);
try file_writer.seekTo(8);
diff --git a/lib/std/posix/test.zig b/lib/std/posix/test.zig
index bacfdacf83..756ecfd63f 100644
--- a/lib/std/posix/test.zig
+++ b/lib/std/posix/test.zig
@@ -690,7 +690,7 @@ test "rename smoke test" {
// Rename the file
const new_file_path = try fs.path.join(a, &.{ base_path, "some_other_file" });
defer a.free(new_file_path);
- try posix.rename(file_path, new_file_path);
+ try Io.Dir.renameAbsolute(file_path, new_file_path);
}
{
@@ -717,7 +717,7 @@ test "rename smoke test" {
// Rename the directory
const new_file_path = try fs.path.join(a, &.{ base_path, "some_other_dir" });
defer a.free(new_file_path);
- try posix.rename(file_path, new_file_path);
+ try Io.Dir.renameAbsolute(file_path, new_file_path);
}
{
diff --git a/lib/std/tar.zig b/lib/std/tar.zig
index b2a5306458..5e7215f1d7 100644
--- a/lib/std/tar.zig
+++ b/lib/std/tar.zig
@@ -612,7 +612,7 @@ pub fn pipeToFileSystem(io: Io, dir: Io.Dir, reader: *Io.Reader, options: PipeOp
.file => {
if (createDirAndFile(io, dir, file_name, fileMode(file.mode, options))) |fs_file| {
defer fs_file.close(io);
- var file_writer = fs_file.writer(&file_contents_buffer);
+ var file_writer = fs_file.writer(io, &file_contents_buffer);
try it.streamRemaining(file, &file_writer.interface);
try file_writer.interface.flush();
} else |err| {
diff --git a/lib/std/zip.zig b/lib/std/zip.zig
index acb3fc65ab..5a91b73d6a 100644
--- a/lib/std/zip.zig
+++ b/lib/std/zip.zig
@@ -570,7 +570,7 @@ pub const Iterator = struct {
};
defer out_file.close(io);
var out_file_buffer: [1024]u8 = undefined;
- var file_writer = out_file.writer(&out_file_buffer);
+ var file_writer = out_file.writer(io, &out_file_buffer);
const local_data_file_offset: u64 =
@as(u64, self.file_offset) +
@as(u64, @sizeOf(LocalFileHeader)) +