authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-18 14:36:50-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:10-08:00
logd8b1cc953eef07079968093babcd1ce3a2020c73
tree35ee87c2c853b19abbd0b36592eebaa395b08a20
parente205b13ffbfe0e57e39bb324799785450c9a1da5

std.Io.Dir.renameAbsolute: consistent parameter order


3 files changed, 52 insertions(+), 66 deletions(-)

lib/std/Io/Dir.zig+1-1
...@@ -982,7 +982,7 @@ pub fn rename(...@@ -982,7 +982,7 @@ pub fn rename(
982 return io.vtable.dirRename(io.userdata, old_dir, old_sub_path, new_dir, new_sub_path);982 return io.vtable.dirRename(io.userdata, old_dir, old_sub_path, new_dir, new_sub_path);
983}983}
984984
985pub fn renameAbsolute(io: Io, old_path: []const u8, new_path: []const u8) RenameError!void {985pub fn renameAbsolute(old_path: []const u8, new_path: []const u8, io: Io) RenameError!void {
986 assert(path.isAbsolute(old_path));986 assert(path.isAbsolute(old_path));
987 assert(path.isAbsolute(new_path));987 assert(path.isAbsolute(new_path));
988 const my_cwd = cwd();988 const my_cwd = cwd();
lib/std/fs/test.zig+49-63
...@@ -251,7 +251,7 @@ test "Dir.readLink on non-symlinks" {...@@ -251,7 +251,7 @@ test "Dir.readLink on non-symlinks" {
251251
252fn testReadLink(io: Io, dir: Dir, target_path: []const u8, symlink_path: []const u8) !void {252fn testReadLink(io: Io, dir: Dir, target_path: []const u8, symlink_path: []const u8) !void {
253 var buffer: [Dir.max_path_bytes]u8 = undefined;253 var buffer: [Dir.max_path_bytes]u8 = undefined;
254 const actual = try dir.readLink(io, symlink_path, &buffer);254 const actual = buffer[0..try dir.readLink(io, symlink_path, &buffer)];
255 try expectEqualStrings(target_path, actual);255 try expectEqualStrings(target_path, actual);
256}256}
257257
...@@ -289,7 +289,7 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {...@@ -289,7 +289,7 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {
289289
290 try setupSymlink(io, ctx.dir, dir_target_path, "symlink", .{ .is_directory = true });290 try setupSymlink(io, ctx.dir, dir_target_path, "symlink", .{ .is_directory = true });
291291
292 var symlink: Dir = try ctx.dir.openDir("symlink", .{ .follow_symlinks = false });292 var symlink: Dir = try ctx.dir.openDir(io, "symlink", .{ .follow_symlinks = false });
293 defer symlink.close(io);293 defer symlink.close(io);
294294
295 const stat = try symlink.stat(io);295 const stat = try symlink.stat(io);
...@@ -807,7 +807,7 @@ test "directory operations on files" {...@@ -807,7 +807,7 @@ test "directory operations on files" {
807 try expectError(error.NotDir, ctx.dir.deleteDir(io, test_file_name));807 try expectError(error.NotDir, ctx.dir.deleteDir(io, test_file_name));
808808
809 if (ctx.path_type == .absolute and comptime PathType.absolute.isSupported(builtin.os)) {809 if (ctx.path_type == .absolute and comptime PathType.absolute.isSupported(builtin.os)) {
810 try expectError(error.PathAlreadyExists, Dir.makeDirAbsolute(io, test_file_name));810 try expectError(error.PathAlreadyExists, Dir.makeDirAbsolute(io, test_file_name, .default_dir));
811 try expectError(error.NotDir, Dir.deleteDirAbsolute(io, test_file_name));811 try expectError(error.NotDir, Dir.deleteDirAbsolute(io, test_file_name));
812 }812 }
813813
...@@ -1104,9 +1104,9 @@ test "renameAbsolute" {...@@ -1104,9 +1104,9 @@ test "renameAbsolute" {
1104 const base_path = try tmp_dir.dir.realPathAlloc(io, ".", allocator);1104 const base_path = try tmp_dir.dir.realPathAlloc(io, ".", allocator);
11051105
1106 try expectError(error.FileNotFound, Dir.renameAbsolute(1106 try expectError(error.FileNotFound, Dir.renameAbsolute(
1107 io,
1108 try Dir.path.join(allocator, &.{ base_path, "missing_file_name" }),1107 try Dir.path.join(allocator, &.{ base_path, "missing_file_name" }),
1109 try Dir.path.join(allocator, &.{ base_path, "something_else" }),1108 try Dir.path.join(allocator, &.{ base_path, "something_else" }),
1109 io,
1110 ));1110 ));
11111111
1112 // Renaming files1112 // Renaming files
...@@ -1115,9 +1115,9 @@ test "renameAbsolute" {...@@ -1115,9 +1115,9 @@ test "renameAbsolute" {
1115 var file = try tmp_dir.dir.createFile(io, test_file_name, .{ .read = true });1115 var file = try tmp_dir.dir.createFile(io, test_file_name, .{ .read = true });
1116 file.close(io);1116 file.close(io);
1117 try Dir.renameAbsolute(1117 try Dir.renameAbsolute(
1118 io,
1119 try Dir.path.join(allocator, &.{ base_path, test_file_name }),1118 try Dir.path.join(allocator, &.{ base_path, test_file_name }),
1120 try Dir.path.join(allocator, &.{ base_path, renamed_test_file_name }),1119 try Dir.path.join(allocator, &.{ base_path, renamed_test_file_name }),
1120 io,
1121 );1121 );
11221122
1123 // ensure the file was renamed1123 // ensure the file was renamed
...@@ -1132,9 +1132,9 @@ test "renameAbsolute" {...@@ -1132,9 +1132,9 @@ test "renameAbsolute" {
1132 const renamed_test_dir_name = "test_dir_renamed";1132 const renamed_test_dir_name = "test_dir_renamed";
1133 try tmp_dir.dir.makeDir(io, test_dir_name, .default_dir);1133 try tmp_dir.dir.makeDir(io, test_dir_name, .default_dir);
1134 try Dir.renameAbsolute(1134 try Dir.renameAbsolute(
1135 io,
1136 try Dir.path.join(allocator, &.{ base_path, test_dir_name }),1135 try Dir.path.join(allocator, &.{ base_path, test_dir_name }),
1137 try Dir.path.join(allocator, &.{ base_path, renamed_test_dir_name }),1136 try Dir.path.join(allocator, &.{ base_path, renamed_test_dir_name }),
1137 io,
1138 );1138 );
11391139
1140 // ensure the directory was renamed1140 // ensure the directory was renamed
...@@ -1430,7 +1430,7 @@ test "writev, readv" {...@@ -1430,7 +1430,7 @@ test "writev, readv" {
1430 var src_file = try tmp.dir.createFile(io, "test.txt", .{ .read = true });1430 var src_file = try tmp.dir.createFile(io, "test.txt", .{ .read = true });
1431 defer src_file.close(io);1431 defer src_file.close(io);
14321432
1433 var writer = src_file.writerStreaming(&.{});1433 var writer = src_file.writerStreaming(io, &.{});
14341434
1435 try writer.interface.writeVecAll(&write_vecs);1435 try writer.interface.writeVecAll(&write_vecs);
1436 try writer.interface.flush();1436 try writer.interface.flush();
...@@ -1590,10 +1590,10 @@ test "copyFile" {...@@ -1590,10 +1590,10 @@ test "copyFile" {
1590 try ctx.dir.writeFile(io, .{ .sub_path = src_file, .data = data });1590 try ctx.dir.writeFile(io, .{ .sub_path = src_file, .data = data });
1591 defer ctx.dir.deleteFile(io, src_file) catch {};1591 defer ctx.dir.deleteFile(io, src_file) catch {};
15921592
1593 try ctx.dir.copyFile(src_file, ctx.dir, dest_file, .{});1593 try ctx.dir.copyFile(src_file, ctx.dir, dest_file, io, .{});
1594 defer ctx.dir.deleteFile(io, dest_file) catch {};1594 defer ctx.dir.deleteFile(io, dest_file) catch {};
15951595
1596 try ctx.dir.copyFile(src_file, ctx.dir, dest_file2, .{ .override_mode = File.default_mode });1596 try ctx.dir.copyFile(src_file, ctx.dir, dest_file2, io, .{ .override_mode = File.default_mode });
1597 defer ctx.dir.deleteFile(io, dest_file2) catch {};1597 defer ctx.dir.deleteFile(io, dest_file2) catch {};
15981598
1599 try expectFileContents(io, ctx.dir, dest_file, data);1599 try expectFileContents(io, ctx.dir, dest_file, data);
...@@ -1968,7 +1968,7 @@ test "'.' and '..' in Dir functions" {...@@ -1968,7 +1968,7 @@ test "'.' and '..' in Dir functions" {
1968 created_file.close(io);1968 created_file.close(io);
1969 try ctx.dir.access(io, file_path, .{});1969 try ctx.dir.access(io, file_path, .{});
19701970
1971 try ctx.dir.copyFile(file_path, ctx.dir, copy_path, .{});1971 try ctx.dir.copyFile(file_path, ctx.dir, copy_path, io, .{});
1972 try ctx.dir.rename(copy_path, ctx.dir, rename_path, io);1972 try ctx.dir.rename(copy_path, ctx.dir, rename_path, io);
1973 const renamed_file = try ctx.dir.openFile(io, rename_path, .{});1973 const renamed_file = try ctx.dir.openFile(io, rename_path, .{});
1974 renamed_file.close(io);1974 renamed_file.close(io);
...@@ -2000,7 +2000,7 @@ test "'.' and '..' in absolute functions" {...@@ -2000,7 +2000,7 @@ test "'.' and '..' in absolute functions" {
2000 const base_path = try tmp.dir.realPathAlloc(io, ".", allocator);2000 const base_path = try tmp.dir.realPathAlloc(io, ".", allocator);
20012001
2002 const subdir_path = try Dir.path.join(allocator, &.{ base_path, "./subdir" });2002 const subdir_path = try Dir.path.join(allocator, &.{ base_path, "./subdir" });
2003 try Dir.makeDirAbsolute(io, subdir_path);2003 try Dir.makeDirAbsolute(io, subdir_path, .default_dir);
2004 try Dir.accessAbsolute(io, subdir_path, .{});2004 try Dir.accessAbsolute(io, subdir_path, .{});
2005 var created_subdir = try Dir.openDirAbsolute(io, subdir_path, .{});2005 var created_subdir = try Dir.openDirAbsolute(io, subdir_path, .{});
2006 created_subdir.close(io);2006 created_subdir.close(io);
...@@ -2011,10 +2011,10 @@ test "'.' and '..' in absolute functions" {...@@ -2011,10 +2011,10 @@ test "'.' and '..' in absolute functions" {
2011 try Dir.accessAbsolute(io, created_file_path, .{});2011 try Dir.accessAbsolute(io, created_file_path, .{});
20122012
2013 const copied_file_path = try Dir.path.join(allocator, &.{ subdir_path, "../copy" });2013 const copied_file_path = try Dir.path.join(allocator, &.{ subdir_path, "../copy" });
2014 try Dir.copyFileAbsolute(io, created_file_path, copied_file_path, .{});2014 try Dir.copyFileAbsolute(created_file_path, copied_file_path, io, .{});
2015 const renamed_file_path = try Dir.path.join(allocator, &.{ subdir_path, "../rename" });2015 const renamed_file_path = try Dir.path.join(allocator, &.{ subdir_path, "../rename" });
2016 try Dir.renameAbsolute(io, copied_file_path, renamed_file_path);2016 try Dir.renameAbsolute(copied_file_path, renamed_file_path, io);
2017 const renamed_file = try Dir.openFileAbsolute(renamed_file_path, .{});2017 const renamed_file = try Dir.openFileAbsolute(io, renamed_file_path, .{});
2018 renamed_file.close(io);2018 renamed_file.close(io);
2019 try Dir.deleteFileAbsolute(io, renamed_file_path);2019 try Dir.deleteFileAbsolute(io, renamed_file_path);
20202020
...@@ -2044,7 +2044,7 @@ test "chmod" {...@@ -2044,7 +2044,7 @@ test "chmod" {
2044 try expectEqual(0o700, (try dir.stat(io)).permissions.toMode() & 0o7777);2044 try expectEqual(0o700, (try dir.stat(io)).permissions.toMode() & 0o7777);
2045}2045}
20462046
2047test "chown" {2047test "change ownership" {
2048 if (native_os == .windows or native_os == .wasi)2048 if (native_os == .windows or native_os == .wasi)
2049 return error.SkipZigTest;2049 return error.SkipZigTest;
20502050
...@@ -2055,13 +2055,13 @@ test "chown" {...@@ -2055,13 +2055,13 @@ test "chown" {
20552055
2056 const file = try tmp.dir.createFile(io, "test_file", .{});2056 const file = try tmp.dir.createFile(io, "test_file", .{});
2057 defer file.close(io);2057 defer file.close(io);
2058 try file.chown(null, null);2058 try file.setOwner(io, null, null);
20592059
2060 try tmp.dir.makeDir(io, "test_dir", .default_dir);2060 try tmp.dir.makeDir(io, "test_dir", .default_dir);
20612061
2062 var dir = try tmp.dir.openDir(io, "test_dir", .{ .iterate = true });2062 var dir = try tmp.dir.openDir(io, "test_dir", .{ .iterate = true });
2063 defer dir.close(io);2063 defer dir.close(io);
2064 try dir.chown(null, null);2064 try dir.setOwner(io, null, null);
2065}2065}
20662066
2067test "invalid UTF-8/WTF-8 paths" {2067test "invalid UTF-8/WTF-8 paths" {
...@@ -2116,7 +2116,7 @@ test "invalid UTF-8/WTF-8 paths" {...@@ -2116,7 +2116,7 @@ test "invalid UTF-8/WTF-8 paths" {
21162116
2117 var dir = ctx.dir;2117 var dir = ctx.dir;
2118 try expectError(expected_err, dir.updateFile(io, invalid_path, dir, invalid_path, .{}));2118 try expectError(expected_err, dir.updateFile(io, invalid_path, dir, invalid_path, .{}));
2119 try expectError(expected_err, ctx.dir.copyFile(invalid_path, ctx.dir, invalid_path, .{}));2119 try expectError(expected_err, ctx.dir.copyFile(invalid_path, ctx.dir, invalid_path, io, .{}));
21202120
2121 try expectError(expected_err, ctx.dir.statFile(invalid_path));2121 try expectError(expected_err, ctx.dir.statFile(invalid_path));
21222122
...@@ -2128,12 +2128,12 @@ test "invalid UTF-8/WTF-8 paths" {...@@ -2128,12 +2128,12 @@ test "invalid UTF-8/WTF-8 paths" {
2128 try expectError(expected_err, Dir.rename(ctx.dir, invalid_path, ctx.dir, invalid_path, io));2128 try expectError(expected_err, Dir.rename(ctx.dir, invalid_path, ctx.dir, invalid_path, io));
21292129
2130 if (native_os != .wasi and ctx.path_type != .relative) {2130 if (native_os != .wasi and ctx.path_type != .relative) {
2131 try expectError(expected_err, Dir.copyFileAbsolute(invalid_path, invalid_path, .{}));2131 try expectError(expected_err, Dir.copyFileAbsolute(invalid_path, invalid_path, io, .{}));
2132 try expectError(expected_err, Dir.makeDirAbsolute(invalid_path));2132 try expectError(expected_err, Dir.makeDirAbsolute(io, invalid_path, .default_dir));
2133 try expectError(expected_err, Dir.deleteDirAbsolute(invalid_path));2133 try expectError(expected_err, Dir.deleteDirAbsolute(invalid_path));
2134 try expectError(expected_err, Dir.renameAbsolute(invalid_path, invalid_path));2134 try expectError(expected_err, Dir.renameAbsolute(invalid_path, invalid_path, io));
2135 try expectError(expected_err, Dir.openDirAbsolute(io, invalid_path, .{}));2135 try expectError(expected_err, Dir.openDirAbsolute(io, invalid_path, .{}));
2136 try expectError(expected_err, Dir.openFileAbsolute(invalid_path, .{}));2136 try expectError(expected_err, Dir.openFileAbsolute(io, invalid_path, .{}));
2137 try expectError(expected_err, Dir.accessAbsolute(invalid_path, .{}));2137 try expectError(expected_err, Dir.accessAbsolute(invalid_path, .{}));
2138 try expectError(expected_err, Dir.createFileAbsolute(invalid_path, .{}));2138 try expectError(expected_err, Dir.createFileAbsolute(invalid_path, .{}));
2139 try expectError(expected_err, Dir.deleteFileAbsolute(invalid_path));2139 try expectError(expected_err, Dir.deleteFileAbsolute(invalid_path));
...@@ -2157,7 +2157,7 @@ test "read file non vectored" {...@@ -2157,7 +2157,7 @@ test "read file non vectored" {
2157 const file = try tmp_dir.dir.createFile(io, "input.txt", .{ .read = true });2157 const file = try tmp_dir.dir.createFile(io, "input.txt", .{ .read = true });
2158 defer file.close(io);2158 defer file.close(io);
2159 {2159 {
2160 var file_writer: File.Writer = .init(file, &.{});2160 var file_writer: File.Writer = .init(file, io, &.{});
2161 try file_writer.interface.writeAll(contents);2161 try file_writer.interface.writeAll(contents);
2162 try file_writer.interface.flush();2162 try file_writer.interface.flush();
2163 }2163 }
...@@ -2189,7 +2189,7 @@ test "seek keeping partial buffer" {...@@ -2189,7 +2189,7 @@ test "seek keeping partial buffer" {
2189 const file = try tmp_dir.dir.createFile(io, "input.txt", .{ .read = true });2189 const file = try tmp_dir.dir.createFile(io, "input.txt", .{ .read = true });
2190 defer file.close(io);2190 defer file.close(io);
2191 {2191 {
2192 var file_writer: File.Writer = .init(file, &.{});2192 var file_writer: File.Writer = .init(file, io, &.{});
2193 try file_writer.interface.writeAll(contents);2193 try file_writer.interface.writeAll(contents);
2194 try file_writer.interface.flush();2194 try file_writer.interface.flush();
2195 }2195 }
...@@ -2251,7 +2251,7 @@ test "seekTo flushes buffered data" {...@@ -2251,7 +2251,7 @@ test "seekTo flushes buffered data" {
2251 defer file.close(io);2251 defer file.close(io);
2252 {2252 {
2253 var buf: [16]u8 = undefined;2253 var buf: [16]u8 = undefined;
2254 var file_writer = file.writer(io, file, &buf);2254 var file_writer = file.writer(io, &buf);
22552255
2256 try file_writer.interface.writeAll(contents);2256 try file_writer.interface.writeAll(contents);
2257 try file_writer.seekTo(8);2257 try file_writer.seekTo(8);
...@@ -2285,7 +2285,7 @@ test "File.Writer sendfile with buffered contents" {...@@ -2285,7 +2285,7 @@ test "File.Writer sendfile with buffered contents" {
2285 try in_r.interface.fill(2);2285 try in_r.interface.fill(2);
22862286
2287 var out_buf: [1]u8 = undefined;2287 var out_buf: [1]u8 = undefined;
2288 var out_w = out.writerStreaming(&out_buf);2288 var out_w = out.writerStreaming(io, &out_buf);
2289 try out_w.interface.writeByte('a');2289 try out_w.interface.writeByte('a');
2290 try expectEqual(3, try out_w.interface.sendFileAll(&in_r, .unlimited));2290 try expectEqual(3, try out_w.interface.sendFileAll(&in_r, .unlimited));
2291 try out_w.interface.flush();2291 try out_w.interface.flush();
...@@ -2325,16 +2325,17 @@ test "readlinkat" {...@@ -2325,16 +2325,17 @@ test "readlinkat" {
2325 try tmp.dir.writeFile(io, .{ .sub_path = "file.txt", .data = "nonsense" });2325 try tmp.dir.writeFile(io, .{ .sub_path = "file.txt", .data = "nonsense" });
23262326
2327 // create a symbolic link2327 // create a symbolic link
2328 tmp.dir.symLink("file.txt", "link", .{}) catch |err| switch (err) {2328 tmp.dir.symLink(io, "file.txt", "link", .{}) catch |err| switch (err) {
2329 error.AccessDenied => {2329 error.AccessDenied => {
2330 // Symlink requires admin privileges on windows, so this test can legitimately fail.2330 // Symlink requires admin privileges on windows, so this test can legitimately fail.
2331 if (native_os == .windows) return error.SkipZigTest;2331 if (native_os == .windows) return error.SkipZigTest;
2332 },2332 },
2333 else => |e| return e,
2333 };2334 };
23342335
2335 // read the link2336 // read the link
2336 var buffer: [Dir.max_path_bytes]u8 = undefined;2337 var buffer: [Dir.max_path_bytes]u8 = undefined;
2337 const read_link = try tmp.dir.readLink(io, "link", &buffer);2338 const read_link = buffer[0..try tmp.dir.readLink(io, "link", &buffer)];
2338 try expectEqualStrings("file.txt", read_link);2339 try expectEqualStrings("file.txt", read_link);
2339}2340}
23402341
...@@ -2351,7 +2352,7 @@ test "fchmodat smoke test" {...@@ -2351,7 +2352,7 @@ test "fchmodat smoke test" {
2351 var tmp = tmpDir(.{});2352 var tmp = tmpDir(.{});
2352 defer tmp.cleanup();2353 defer tmp.cleanup();
23532354
2354 try expectError(error.FileNotFound, tmp.dir.setPermissions(io, "regfile", 0o666, .{}));2355 try expectError(error.FileNotFound, tmp.dir.setFilePermissions(io, "regfile", .fromMode(0o666), .{}));
2355 const file = try tmp.dir.createFile(io, "regfile", .{2356 const file = try tmp.dir.createFile(io, "regfile", .{
2356 .exclusive = true,2357 .exclusive = true,
2357 .permissions = .fromMode(0o644),2358 .permissions = .fromMode(0o644),
...@@ -2384,15 +2385,15 @@ test "fchmodat smoke test" {...@@ -2384,15 +2385,15 @@ test "fchmodat smoke test" {
2384 error.OperationNotSupported => test_link = false,2385 error.OperationNotSupported => test_link = false,
2385 else => |e| return e,2386 else => |e| return e,
2386 };2387 };
2387 if (test_link)2388 if (test_link) try expectMode(io, tmp.dir, "symlink", .fromMode(0o600));
2388 try expectMode(tmp.dir.handle, "symlink", 0o600);2389 try expectMode(io, tmp.dir, "regfile", .fromMode(0o640));
2389 try expectMode(tmp.dir.handle, "regfile", 0o640);
2390}2390}
23912391
2392fn expectMode(io: Io, dir: Dir, file: []const u8, permissions: File.Permissions) !void {2392fn expectMode(io: Io, dir: Dir, file: []const u8, permissions: File.Permissions) !void {
2393 const mode = permissions.toMode();2393 const mode = permissions.toMode();
2394 const st = try dir.statFile(io, file, .{ .follow_symlinks = false });2394 const st = try dir.statFile(io, file, .{ .follow_symlinks = false });
2395 try expectEqual(mode, st.mode & 0b111_111_111);2395 const found_mode = st.permissions.toMode();
2396 try expectEqual(mode, found_mode & 0b111_111_111);
2396}2397}
23972398
2398test "isatty" {2399test "isatty" {
...@@ -2417,7 +2418,7 @@ test "read positional empty buffer" {...@@ -2417,7 +2418,7 @@ test "read positional empty buffer" {
2417 defer file.close(io);2418 defer file.close(io);
24182419
2419 var buffer: [0]u8 = undefined;2420 var buffer: [0]u8 = undefined;
2420 try expectEqual(0, try file.readPositional(io, &buffer, 0));2421 try expectEqual(0, try file.readPositional(io, &.{&buffer}, 0));
2421}2422}
24222423
2423test "write streaming empty buffer" {2424test "write streaming empty buffer" {
...@@ -2429,8 +2430,8 @@ test "write streaming empty buffer" {...@@ -2429,8 +2430,8 @@ test "write streaming empty buffer" {
2429 var file = try tmp.dir.createFile(io, "write_empty", .{});2430 var file = try tmp.dir.createFile(io, "write_empty", .{});
2430 defer file.close(io);2431 defer file.close(io);
24312432
2432 var buffer: [0]u8 = &.{};2433 const buffer: [0]u8 = .{};
2433 try expectEqual(0, try file.writeStreaming(io, &buffer));2434 try file.writeStreamingAll(io, &buffer);
2434}2435}
24352436
2436test "write positional empty buffer" {2437test "write positional empty buffer" {
...@@ -2442,8 +2443,8 @@ test "write positional empty buffer" {...@@ -2442,8 +2443,8 @@ test "write positional empty buffer" {
2442 var file = try tmp.dir.createFile(io, "pwrite_empty", .{});2443 var file = try tmp.dir.createFile(io, "pwrite_empty", .{});
2443 defer file.close(io);2444 defer file.close(io);
24442445
2445 var buffer: [0]u8 = &.{};2446 const buffer: [0]u8 = .{};
2446 try expectEqual(0, try file.writePositional(io, &buffer, 0));2447 try expectEqual(0, try file.writePositional(io, &.{&buffer}, 0));
2447}2448}
24482449
2449test "access smoke test" {2450test "access smoke test" {
...@@ -2452,53 +2453,38 @@ test "access smoke test" {...@@ -2452,53 +2453,38 @@ test "access smoke test" {
2452 if (native_os == .openbsd) return error.SkipZigTest;2453 if (native_os == .openbsd) return error.SkipZigTest;
24532454
2454 const io = testing.io;2455 const io = testing.io;
2455 const gpa = testing.allocator;
24562456
2457 var tmp = tmpDir(.{});2457 var tmp = tmpDir(.{});
2458 defer tmp.cleanup();2458 defer tmp.cleanup();
24592459
2460 const base_path = try tmp.dir.realPathAlloc(io, ".", gpa);
2461 defer gpa.free(base_path);
2462
2463 {2460 {
2464 // Create some file using `open`.2461 // Create some file using `open`.
2465 const file_path = try Dir.path.join(gpa, &.{ base_path, "some_file" });2462 const file = try tmp.dir.createFile(io, "some_file", .{ .read = true, .exclusive = true });
2466 defer gpa.free(file_path);
2467 const file = Dir.cwd().createFile(io, file_path, .{ .read = true, .exclusive = true });
2468 file.close(io);2463 file.close(io);
2469 }2464 }
24702465
2471 {2466 {
2472 // Try to access() the file2467 // Try to access() the file
2473 const file_path = try Dir.path.join(gpa, &.{ base_path, "some_file" });
2474 defer gpa.free(file_path);
2475 if (native_os == .windows) {2468 if (native_os == .windows) {
2476 try Dir.cwd().access(io, file_path, .{});2469 try tmp.dir.access(io, "some_file", .{});
2477 } else {2470 } else {
2478 try Dir.cwd().access(io, file_path, .{ .read = true, .write = true });2471 try tmp.dir.access(io, "some_file", .{ .read = true, .write = true });
2479 }2472 }
2480 }2473 }
24812474
2482 {2475 {
2483 // Try to access() a non-existent file - should fail with error.FileNotFound2476 // Try to access() a non-existent file - should fail with error.FileNotFound
2484 const file_path = try Dir.path.join(gpa, &.{ base_path, "some_other_file" });2477 try expectError(error.FileNotFound, tmp.dir.access(io, "some_other_file", .{}));
2485 defer gpa.free(file_path);
2486 try expectError(error.FileNotFound, Dir.cwd().access(io, file_path, .{}));
2487 }2478 }
24882479
2489 {2480 {
2490 // Create some directory2481 // Create some directory
2491 const file_path = try Dir.path.join(gpa, &.{ base_path, "some_dir" });2482 try tmp.dir.makeDir(io, "some_dir", .default_file);
2492 defer gpa.free(file_path);
2493 try Dir.makeDir(io, file_path, .default_file);
2494 }2483 }
24952484
2496 {2485 {
2497 // Try to access() the directory2486 // Try to access() the directory
2498 const file_path = try Dir.path.join(gpa, &.{ base_path, "some_dir" });2487 try tmp.dir.access(io, "some_dir", .{});
2499 defer gpa.free(file_path);
2500
2501 try Dir.access(io, file_path, .{});
2502 }2488 }
2503}2489}
25042490
...@@ -2552,12 +2538,12 @@ test "open smoke test" {...@@ -2552,12 +2538,12 @@ test "open smoke test" {
2552 try tmp.dir.makeDir(io, "some_dir", .default_dir);2538 try tmp.dir.makeDir(io, "some_dir", .default_dir);
25532539
2554 {2540 {
2555 const dir = try tmp.dir.openDir("some_dir", .{});2541 const dir = try tmp.dir.openDir(io, "some_dir", .{});
2556 dir.close(io);2542 dir.close(io);
2557 }2543 }
25582544
2559 // Try opening as file which should fail.2545 // Try opening as file which should fail.
2560 try expectError(error.IsDir, tmp.dir.openFile("some_dir", .{}));2546 try expectError(error.IsDir, tmp.dir.openFile(io, "some_dir", .{}));
2561}2547}
25622548
2563test "hard link with different directories" {2549test "hard link with different directories" {
...@@ -2575,7 +2561,7 @@ test "hard link with different directories" {...@@ -2575,7 +2561,7 @@ test "hard link with different directories" {
2575 try tmp.dir.writeFile(io, .{ .sub_path = target_name, .data = "example" });2561 try tmp.dir.writeFile(io, .{ .sub_path = target_name, .data = "example" });
25762562
2577 // Test 1: link from file in subdir back up to target in parent directory2563 // Test 1: link from file in subdir back up to target in parent directory
2578 tmp.dir.hardLink(target_name, subdir, link_name, 0) catch |err| switch (err) {2564 tmp.dir.hardLink(target_name, subdir, link_name, io, .{}) catch |err| switch (err) {
2579 error.OperationUnsupported => return error.SkipZigTest,2565 error.OperationUnsupported => return error.SkipZigTest,
2580 else => |e| return e,2566 else => |e| return e,
2581 };2567 };
...@@ -2596,7 +2582,7 @@ test "hard link with different directories" {...@@ -2596,7 +2582,7 @@ test "hard link with different directories" {
2596 }2582 }
25972583
2598 // Test 2: remove link2584 // Test 2: remove link
2599 try subdir.deleteFile(io, link_name, .{});2585 try subdir.deleteFile(io, link_name);
2600 const e_stat = try efd.stat(io);2586 const e_stat = try efd.stat(io);
2601 try expectEqual(1, e_stat.nlink);2587 try expectEqual(1, e_stat.nlink);
2602}2588}
lib/std/posix/test.zig+2-2
...@@ -518,7 +518,7 @@ test "rename smoke test" {...@@ -518,7 +518,7 @@ test "rename smoke test" {
518 // Rename the file518 // Rename the file
519 const new_file_path = try Dir.path.join(gpa, &.{ base_path, "some_other_file" });519 const new_file_path = try Dir.path.join(gpa, &.{ base_path, "some_other_file" });
520 defer gpa.free(new_file_path);520 defer gpa.free(new_file_path);
521 try Io.Dir.renameAbsolute(io, file_path, new_file_path);521 try Io.Dir.renameAbsolute(file_path, new_file_path, io);
522 }522 }
523523
524 {524 {
...@@ -545,7 +545,7 @@ test "rename smoke test" {...@@ -545,7 +545,7 @@ test "rename smoke test" {
545 // Rename the directory545 // Rename the directory
546 const new_file_path = try Dir.path.join(gpa, &.{ base_path, "some_other_dir" });546 const new_file_path = try Dir.path.join(gpa, &.{ base_path, "some_other_dir" });
547 defer gpa.free(new_file_path);547 defer gpa.free(new_file_path);
548 try Io.Dir.renameAbsolute(io, file_path, new_file_path);548 try Io.Dir.renameAbsolute(file_path, new_file_path, io);
549 }549 }
550550
551 {551 {