authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-08 19:41:21-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:08-08:00
logebdbbd20ace6e93b581b90075f52946b3832da93
tree09fb393f4a4578512ddf4906c7df14df5f6f9255
parent3725f72293c87a73e0c11e74739574c7b78bb53d

update makeDir() sites to specify permissions


16 files changed, 102 insertions(+), 97 deletions(-)

lib/compiler/reduce.zig+8-8
......@@ -92,9 +92,7 @@ pub fn main() !void {
9292 if (i >= args.len) fatal("expected 32-bit integer after {s}", .{arg});
9393 const next_arg = args[i];
9494 seed = std.fmt.parseUnsigned(u32, next_arg, 0) catch |err| {
95 fatal("unable to parse seed '{s}' as 32-bit integer: {s}", .{
96 next_arg, @errorName(err),
97 });
95 fatal("unable to parse seed '{s}' as 32-bit integer: {t}", .{ next_arg, err });
9896 };
9997 } else {
10098 fatal("unrecognized parameter: '{s}'", .{arg});
......@@ -125,7 +123,7 @@ pub fn main() !void {
125123 var astgen_input: std.Io.Writer.Allocating = .init(gpa);
126124 defer astgen_input.deinit();
127125
128 var tree = try parse(gpa, root_source_file_path);
126 var tree = try parse(gpa, io, root_source_file_path);
129127 defer {
130128 gpa.free(tree.source);
131129 tree.deinit(gpa);
......@@ -190,7 +188,7 @@ pub fn main() !void {
190188 std.debug.print("{s} ", .{@tagName(t)});
191189 }
192190 std.debug.print("\n", .{});
193 try transformationsToFixups(gpa, arena, root_source_file_path, this_set, &fixups);
191 try transformationsToFixups(gpa, arena, io, root_source_file_path, this_set, &fixups);
194192
195193 rendered.clearRetainingCapacity();
196194 try tree.render(gpa, &rendered.writer, fixups);
......@@ -246,7 +244,7 @@ pub fn main() !void {
246244 });
247245 switch (interestingness) {
248246 .interesting => {
249 const new_tree = try parse(gpa, root_source_file_path);
247 const new_tree = try parse(gpa, io, root_source_file_path);
250248 gpa.free(tree.source);
251249 tree.deinit(gpa);
252250 tree = new_tree;
......@@ -317,6 +315,7 @@ fn runCheck(arena: Allocator, io: Io, argv: []const []const u8) !Interestingness
317315fn transformationsToFixups(
318316 gpa: Allocator,
319317 arena: Allocator,
318 io: Io,
320319 root_source_file_path: []const u8,
321320 transforms: []const Walk.Transformation,
322321 fixups: *Ast.Render.Fixups,
......@@ -354,7 +353,7 @@ fn transformationsToFixups(
354353 inline_imported_file.imported_string,
355354 });
356355 defer gpa.free(full_imported_path);
357 var other_file_ast = try parse(gpa, full_imported_path);
356 var other_file_ast = try parse(gpa, io, full_imported_path);
358357 defer {
359358 gpa.free(other_file_ast.source);
360359 other_file_ast.deinit(gpa);
......@@ -398,8 +397,9 @@ fn transformationsToFixups(
398397 };
399398}
400399
401fn parse(gpa: Allocator, file_path: []const u8) !Ast {
400fn parse(gpa: Allocator, io: Io, file_path: []const u8) !Ast {
402401 const source_code = Io.Dir.cwd().readFileAllocOptions(
402 io,
403403 file_path,
404404 gpa,
405405 .limited(std.math.maxInt(u32)),
lib/std/Build/Step/CheckObject.zig+2
......@@ -547,12 +547,14 @@ pub fn checkComputeCompare(
547547fn make(step: *Step, make_options: Step.MakeOptions) !void {
548548 _ = make_options;
549549 const b = step.owner;
550 const io = b.graph.io;
550551 const gpa = b.allocator;
551552 const check_object: *CheckObject = @fieldParentPtr("step", step);
552553 try step.singleUnchangingWatchInput(check_object.source);
553554
554555 const src_path = check_object.source.getPath3(b, step);
555556 const contents = src_path.root_dir.handle.readFileAllocOptions(
557 io,
556558 src_path.sub_path,
557559 gpa,
558560 .limited(check_object.max_bytes),
lib/std/Build/Step/RemoveDir.zig+4-7
......@@ -27,6 +27,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
2727 _ = options;
2828
2929 const b = step.owner;
30 const io = b.graph.io;
3031 const remove_dir: *RemoveDir = @fieldParentPtr("step", step);
3132
3233 step.clearWatchInputs();
......@@ -34,15 +35,11 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
3435
3536 const full_doomed_path = remove_dir.doomed_path.getPath2(b, step);
3637
37 b.build_root.handle.deleteTree(full_doomed_path) catch |err| {
38 b.build_root.handle.deleteTree(io, full_doomed_path) catch |err| {
3839 if (b.build_root.path) |base| {
39 return step.fail("unable to recursively delete path '{s}/{s}': {s}", .{
40 base, full_doomed_path, @errorName(err),
41 });
40 return step.fail("unable to recursively delete path '{s}/{s}': {t}", .{ base, full_doomed_path, err });
4241 } else {
43 return step.fail("unable to recursively delete path '{s}': {s}", .{
44 full_doomed_path, @errorName(err),
45 });
42 return step.fail("unable to recursively delete path '{s}': {t}", .{ full_doomed_path, err });
4643 }
4744 };
4845}
lib/std/Build/Step/Run.zig+1-1
......@@ -1044,7 +1044,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
10441044
10451045 b.cache_root.handle.rename(tmp_dir_path, b.cache_root.handle, o_sub_path, io) catch |err| {
10461046 if (err == error.PathAlreadyExists) {
1047 b.cache_root.handle.deleteTree(o_sub_path) catch |del_err| {
1047 b.cache_root.handle.deleteTree(io, o_sub_path) catch |del_err| {
10481048 return step.fail("unable to remove dir '{f}'{s}: {t}", .{
10491049 b.cache_root, tmp_dir_path, del_err,
10501050 });
lib/std/fs/test.zig+35-35
......@@ -186,7 +186,7 @@ test "Dir.readLink" {
186186 const file_target_path = try ctx.transformPath("file.txt");
187187 try ctx.dir.writeFile(io, .{ .sub_path = file_target_path, .data = "nonsense" });
188188 const dir_target_path = try ctx.transformPath("subdir");
189 try ctx.dir.makeDir(dir_target_path);
189 try ctx.dir.makeDir(io, dir_target_path, .default_dir);
190190
191191 // On Windows, symlink targets always use the canonical path separator
192192 const canonical_file_target_path = try ctx.toCanonicalPathSep(file_target_path);
......@@ -282,7 +282,7 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {
282282 try testWithAllSupportedPathTypes(struct {
283283 fn impl(ctx: *TestContext) !void {
284284 const dir_target_path = try ctx.transformPath("subdir");
285 try ctx.dir.makeDir(dir_target_path);
285 try ctx.dir.makeDir(io, dir_target_path, .default_dir);
286286
287287 try setupSymlink(ctx.dir, dir_target_path, "symlink", .{ .is_directory = true });
288288
......@@ -363,7 +363,7 @@ test "openDir" {
363363 fn impl(ctx: *TestContext) !void {
364364 const allocator = ctx.arena.allocator();
365365 const subdir_path = try ctx.transformPath("subdir");
366 try ctx.dir.makeDir(subdir_path);
366 try ctx.dir.makeDir(io, subdir_path, .default_dir);
367367
368368 for ([_][]const u8{ "", ".", ".." }) |sub_path| {
369369 const dir_path = try fs.path.join(allocator, &.{ subdir_path, sub_path });
......@@ -398,7 +398,7 @@ test "openDirAbsolute" {
398398
399399 const tmp_ino = (try tmp.dir.stat(io)).inode;
400400
401 try tmp.dir.makeDir("subdir");
401 try tmp.dir.makeDir(io, "subdir", .default_dir);
402402 const sub_path = try tmp.dir.realpathAlloc(testing.allocator, "subdir");
403403 defer testing.allocator.free(sub_path);
404404
......@@ -494,7 +494,7 @@ test "readLinkAbsolute" {
494494
495495 // Create some targets
496496 try tmp.dir.writeFile(io, .{ .sub_path = "file.txt", .data = "nonsense" });
497 try tmp.dir.makeDir("subdir");
497 try tmp.dir.makeDir(io, "subdir", .default_dir);
498498
499499 // Get base abs path
500500 var arena = ArenaAllocator.init(testing.allocator);
......@@ -531,7 +531,7 @@ test "Dir.Iterator" {
531531 const file = try tmp_dir.dir.createFile(io, "some_file", .{});
532532 file.close(io);
533533
534 try tmp_dir.dir.makeDir("some_dir");
534 try tmp_dir.dir.makeDir(io, "some_dir", .default_dir);
535535
536536 var arena = ArenaAllocator.init(testing.allocator);
537537 defer arena.deinit();
......@@ -600,7 +600,7 @@ test "Dir.Iterator twice" {
600600 const file = try tmp_dir.dir.createFile(io, "some_file", .{});
601601 file.close(io);
602602
603 try tmp_dir.dir.makeDir("some_dir");
603 try tmp_dir.dir.makeDir(io, "some_dir", .default_dir);
604604
605605 var arena = ArenaAllocator.init(testing.allocator);
606606 defer arena.deinit();
......@@ -635,7 +635,7 @@ test "Dir.Iterator reset" {
635635 const file = try tmp_dir.dir.createFile(io, "some_file", .{});
636636 file.close(io);
637637
638 try tmp_dir.dir.makeDir("some_dir");
638 try tmp_dir.dir.makeDir(io, "some_dir", .default_dir);
639639
640640 var arena = ArenaAllocator.init(testing.allocator);
641641 defer arena.deinit();
......@@ -682,7 +682,7 @@ test "Dir.Iterator but dir is deleted during iteration" {
682682 // This is a contrived reproduction, but this could happen outside of the program, in another thread, etc.
683683 // If we get an error while trying to delete, we can skip this test (this will happen on platforms
684684 // like Windows which will give FileBusy if the directory is currently open for iteration).
685 tmp.dir.deleteTree("subdir") catch return error.SkipZigTest;
685 tmp.dir.deleteTree(io, "subdir") catch return error.SkipZigTest;
686686
687687 // Now, when we try to iterate, the next call should return null immediately.
688688 const entry = try iterator.next();
......@@ -724,7 +724,7 @@ test "Dir.realpath smoke test" {
724724
725725 // Now create the file and dir
726726 try ctx.dir.writeFile(io, .{ .sub_path = test_file_path, .data = "" });
727 try ctx.dir.makeDir(test_dir_path);
727 try ctx.dir.makeDir(io, test_dir_path, .default_dir);
728728
729729 const base_path = try ctx.transformPath(".");
730730 const base_realpath = try ctx.dir.realpathAlloc(allocator, base_path);
......@@ -842,7 +842,7 @@ test "directory operations on files" {
842842 var file = try ctx.dir.createFile(io, test_file_name, .{ .read = true });
843843 file.close(io);
844844
845 try testing.expectError(error.PathAlreadyExists, ctx.dir.makeDir(test_file_name));
845 try testing.expectError(error.PathAlreadyExists, ctx.dir.makeDir(io, test_file_name, .default_dir));
846846 try testing.expectError(error.NotDir, ctx.dir.openDir(io, test_file_name, .{}));
847847 try testing.expectError(error.NotDir, ctx.dir.deleteDir(test_file_name));
848848
......@@ -870,7 +870,7 @@ test "file operations on directories" {
870870 fn impl(ctx: *TestContext) !void {
871871 const test_dir_name = try ctx.transformPath("test_dir");
872872
873 try ctx.dir.makeDir(test_dir_name);
873 try ctx.dir.makeDir(io, test_dir_name, .default_dir);
874874
875875 try testing.expectError(error.IsDir, ctx.dir.createFile(io, test_dir_name, .{}));
876876 try testing.expectError(error.IsDir, ctx.dir.deleteFile(test_dir_name));
......@@ -937,7 +937,7 @@ test "deleteDir" {
937937 try testing.expectError(error.FileNotFound, ctx.dir.deleteDir(test_dir_path));
938938
939939 // deleting a non-empty directory
940 try ctx.dir.makeDir(test_dir_path);
940 try ctx.dir.makeDir(io, test_dir_path, .default_dir);
941941 try ctx.dir.writeFile(io, .{ .sub_path = test_file_path, .data = "" });
942942 try testing.expectError(error.DirNotEmpty, ctx.dir.deleteDir(test_dir_path));
943943
......@@ -1006,7 +1006,7 @@ test "Dir.rename directories" {
10061006 const test_dir_renamed_path = try ctx.transformPath("test_dir_renamed");
10071007
10081008 // Renaming directories
1009 try ctx.dir.makeDir(test_dir_path);
1009 try ctx.dir.makeDir(io, test_dir_path, .default_dir);
10101010 try ctx.dir.rename(test_dir_path, ctx.dir, test_dir_renamed_path, io);
10111011
10121012 // Ensure the directory was renamed
......@@ -1042,8 +1042,8 @@ test "Dir.rename directory onto empty dir" {
10421042 const test_dir_path = try ctx.transformPath("test_dir");
10431043 const target_dir_path = try ctx.transformPath("target_dir_path");
10441044
1045 try ctx.dir.makeDir(test_dir_path);
1046 try ctx.dir.makeDir(target_dir_path);
1045 try ctx.dir.makeDir(io, test_dir_path, .default_dir);
1046 try ctx.dir.makeDir(io, target_dir_path, .default_dir);
10471047 try ctx.dir.rename(test_dir_path, ctx.dir, target_dir_path, io);
10481048
10491049 // Ensure the directory was renamed
......@@ -1064,7 +1064,7 @@ test "Dir.rename directory onto non-empty dir" {
10641064 const test_dir_path = try ctx.transformPath("test_dir");
10651065 const target_dir_path = try ctx.transformPath("target_dir_path");
10661066
1067 try ctx.dir.makeDir(test_dir_path);
1067 try ctx.dir.makeDir(io, test_dir_path, .default_dir);
10681068
10691069 var target_dir = try ctx.dir.makeOpenPath(target_dir_path, .{});
10701070 var file = try target_dir.createFile(io, "test_file", .{ .read = true });
......@@ -1093,7 +1093,7 @@ test "Dir.rename file <-> dir" {
10931093
10941094 var file = try ctx.dir.createFile(io, test_file_path, .{ .read = true });
10951095 file.close(io);
1096 try ctx.dir.makeDir(test_dir_path);
1096 try ctx.dir.makeDir(io, test_dir_path, .default_dir);
10971097 try testing.expectError(error.IsDir, ctx.dir.rename(test_file_path, ctx.dir, test_dir_path, io));
10981098 try testing.expectError(error.NotDir, ctx.dir.rename(test_dir_path, ctx.dir, test_file_path, io));
10991099 }
......@@ -1163,7 +1163,7 @@ test "renameAbsolute" {
11631163 // Renaming directories
11641164 const test_dir_name = "test_dir";
11651165 const renamed_test_dir_name = "test_dir_renamed";
1166 try tmp_dir.dir.makeDir(test_dir_name);
1166 try tmp_dir.dir.makeDir(io, test_dir_name, .default_dir);
11671167 try fs.renameAbsolute(
11681168 try fs.path.join(allocator, &.{ base_path, test_dir_name }),
11691169 try fs.path.join(allocator, &.{ base_path, renamed_test_dir_name }),
......@@ -1209,7 +1209,7 @@ test "deleteTree does not follow symlinks" {
12091209 try setupSymlink(a, "../b", "b", .{ .is_directory = true });
12101210 }
12111211
1212 try tmp.dir.deleteTree("a");
1212 try tmp.dir.deleteTree(io, "a");
12131213
12141214 try testing.expectError(error.FileNotFound, tmp.dir.access(io, "a", .{}));
12151215 try tmp.dir.access(io, "b", .{});
......@@ -1225,7 +1225,7 @@ test "deleteTree on a symlink" {
12251225 try tmp.dir.writeFile(io, .{ .sub_path = "file", .data = "" });
12261226 try setupSymlink(tmp.dir, "file", "filelink", .{});
12271227
1228 try tmp.dir.deleteTree("filelink");
1228 try tmp.dir.deleteTree(io, "filelink");
12291229 try testing.expectError(error.FileNotFound, tmp.dir.access(io, "filelink", .{}));
12301230 try tmp.dir.access(io, "file", .{});
12311231
......@@ -1233,7 +1233,7 @@ test "deleteTree on a symlink" {
12331233 try tmp.dir.makePath(io, "dir");
12341234 try setupSymlink(tmp.dir, "dir", "dirlink", .{ .is_directory = true });
12351235
1236 try tmp.dir.deleteTree("dirlink");
1236 try tmp.dir.deleteTree(io, "dirlink");
12371237 try testing.expectError(error.FileNotFound, tmp.dir.access(io, "dirlink", .{}));
12381238 try tmp.dir.access(io, "dir", .{});
12391239}
......@@ -1255,7 +1255,7 @@ test "makePath, put some files in it, deleteTree" {
12551255 .data = "blah",
12561256 });
12571257
1258 try ctx.dir.deleteTree(dir_path);
1258 try ctx.dir.deleteTree(io, dir_path);
12591259 try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, dir_path, .{}));
12601260 }
12611261 }.impl);
......@@ -1291,7 +1291,7 @@ test "makePath in a directory that no longer exists" {
12911291
12921292 var tmp = tmpDir(.{});
12931293 defer tmp.cleanup();
1294 try tmp.parent_dir.deleteTree(&tmp.sub_path);
1294 try tmp.parent_dir.deleteTree(io, &tmp.sub_path);
12951295
12961296 try testing.expectError(error.FileNotFound, tmp.dir.makePath(io, "sub-path"));
12971297}
......@@ -1302,7 +1302,7 @@ test "makePath but sub_path contains pre-existing file" {
13021302 var tmp = tmpDir(.{});
13031303 defer tmp.cleanup();
13041304
1305 try tmp.dir.makeDir("foo");
1305 try tmp.dir.makeDir(io, "foo", .default_dir);
13061306 try tmp.dir.writeFile(io, .{ .sub_path = "foo/bar", .data = "" });
13071307
13081308 try testing.expectError(error.NotDir, tmp.dir.makePath(io, "foo/bar/baz"));
......@@ -1319,10 +1319,10 @@ test "makepath existing directories" {
13191319 var tmp = tmpDir(.{});
13201320 defer tmp.cleanup();
13211321
1322 try tmp.dir.makeDir("A");
1322 try tmp.dir.makeDir(io, "A", .default_dir);
13231323 var tmpA = try tmp.dir.openDir(io, "A", .{});
13241324 defer tmpA.close(io);
1325 try tmpA.makeDir("B");
1325 try tmpA.makeDir(io, "B", .default_dir);
13261326
13271327 const testPath = "A" ++ fs.path.sep_str ++ "B" ++ fs.path.sep_str ++ "C";
13281328 try tmp.dir.makePath(io, testPath);
......@@ -1336,7 +1336,7 @@ test "makepath through existing valid symlink" {
13361336 var tmp = tmpDir(.{});
13371337 defer tmp.cleanup();
13381338
1339 try tmp.dir.makeDir("realfolder");
1339 try tmp.dir.makeDir(io, "realfolder", .default_dir);
13401340 try setupSymlink(tmp.dir, "." ++ fs.path.sep_str ++ "realfolder", "working-symlink", .{});
13411341
13421342 try tmp.dir.makePath(io, "working-symlink" ++ fs.path.sep_str ++ "in-realfolder");
......@@ -1419,7 +1419,7 @@ fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8) !vo
14191419 }
14201420
14211421 // ensure that we can delete the tree
1422 try iterable_dir.deleteTree(maxed_filename);
1422 try iterable_dir.deleteTree(io, maxed_filename);
14231423}
14241424
14251425test "max file name component lengths" {
......@@ -1570,7 +1570,7 @@ test "access file" {
15701570
15711571 try ctx.dir.writeFile(io, .{ .sub_path = file_path, .data = "" });
15721572 try ctx.dir.access(io, file_path, .{});
1573 try ctx.dir.deleteTree(dir_path);
1573 try ctx.dir.deleteTree(io, dir_path);
15741574 }
15751575 }.impl);
15761576}
......@@ -2042,7 +2042,7 @@ test "'.' and '..' in Io.Dir functions" {
20422042 const rename_path = try ctx.transformPath("./subdir/../rename");
20432043 const update_path = try ctx.transformPath("./subdir/../update");
20442044
2045 try ctx.dir.makeDir(subdir_path);
2045 try ctx.dir.makeDir(io, subdir_path, .default_dir);
20462046 try ctx.dir.access(io, subdir_path, .{});
20472047 var created_subdir = try ctx.dir.openDir(io, subdir_path, .{});
20482048 created_subdir.close(io);
......@@ -2120,7 +2120,7 @@ test "chmod" {
21202120 try file.chmod(0o644);
21212121 try testing.expectEqual(@as(File.Mode, 0o644), (try file.stat(io)).mode & 0o7777);
21222122
2123 try tmp.dir.makeDir("test_dir");
2123 try tmp.dir.makeDir(io, "test_dir", .default_dir);
21242124 var dir = try tmp.dir.openDir(io, "test_dir", .{ .iterate = true });
21252125 defer dir.close(io);
21262126
......@@ -2141,7 +2141,7 @@ test "chown" {
21412141 defer file.close(io);
21422142 try file.chown(null, null);
21432143
2144 try tmp.dir.makeDir("test_dir");
2144 try tmp.dir.makeDir(io, "test_dir", .default_dir);
21452145
21462146 var dir = try tmp.dir.openDir(io, "test_dir", .{ .iterate = true });
21472147 defer dir.close(io);
......@@ -2165,7 +2165,7 @@ test "invalid UTF-8/WTF-8 paths" {
21652165
21662166 try testing.expectError(expected_err, ctx.dir.createFile(invalid_path, .{}));
21672167
2168 try testing.expectError(expected_err, ctx.dir.makeDir(invalid_path));
2168 try testing.expectError(expected_err, ctx.dir.makeDir(invalid_path, .default_dir));
21692169
21702170 try testing.expectError(expected_err, ctx.dir.makePath(invalid_path));
21712171 try testing.expectError(expected_err, ctx.dir.makeOpenPath(invalid_path, .{}));
......@@ -2191,7 +2191,7 @@ test "invalid UTF-8/WTF-8 paths" {
21912191 try testing.expectError(expected_err, ctx.dir.readFile(invalid_path, &[_]u8{}));
21922192 try testing.expectError(expected_err, ctx.dir.readFileAlloc(invalid_path, testing.allocator, .limited(0)));
21932193
2194 try testing.expectError(expected_err, ctx.dir.deleteTree(invalid_path));
2194 try testing.expectError(expected_err, ctx.dir.deleteTree(io, invalid_path));
21952195 try testing.expectError(expected_err, ctx.dir.deleteTreeMinStackSize(invalid_path));
21962196
21972197 try testing.expectError(expected_err, ctx.dir.writeFile(io, .{ .sub_path = invalid_path, .data = "" }));
lib/std/testing.zig+1-1
......@@ -616,7 +616,7 @@ pub const TmpDir = struct {
616616
617617 pub fn cleanup(self: *TmpDir) void {
618618 self.dir.close(io);
619 self.parent_dir.deleteTree(&self.sub_path) catch {};
619 self.parent_dir.deleteTree(io, &self.sub_path) catch {};
620620 self.parent_dir.close(io);
621621 self.* = undefined;
622622 }
src/Compilation.zig+8-14
......@@ -2823,12 +2823,9 @@ fn cleanupAfterUpdate(comp: *Compilation, tmp_dir_rand_int: u64) void {
28232823 return;
28242824 }
28252825 const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int);
2826 comp.dirs.local_cache.handle.deleteTree(tmp_dir_sub_path) catch |err| {
2827 log.warn("failed to delete temporary directory '{s}{c}{s}': {s}", .{
2828 comp.dirs.local_cache.path orelse ".",
2829 fs.path.sep,
2830 tmp_dir_sub_path,
2831 @errorName(err),
2826 comp.dirs.local_cache.handle.deleteTree(io, tmp_dir_sub_path) catch |err| {
2827 log.warn("failed to delete temporary directory '{s}{c}{s}': {t}", .{
2828 comp.dirs.local_cache.path orelse ".", fs.path.sep, tmp_dir_sub_path, err,
28322829 });
28332830 };
28342831 }
......@@ -2847,12 +2844,9 @@ fn cleanupAfterUpdate(comp: *Compilation, tmp_dir_rand_int: u64) void {
28472844 tmp_dir.handle.close(io);
28482845 whole.tmp_artifact_directory = null;
28492846 const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int);
2850 comp.dirs.local_cache.handle.deleteTree(tmp_dir_sub_path) catch |err| {
2851 log.warn("failed to delete temporary directory '{s}{c}{s}': {s}", .{
2852 comp.dirs.local_cache.path orelse ".",
2853 fs.path.sep,
2854 tmp_dir_sub_path,
2855 @errorName(err),
2847 comp.dirs.local_cache.handle.deleteTree(io, tmp_dir_sub_path) catch |err| {
2848 log.warn("failed to delete temporary directory '{s}{c}{s}': {t}", .{
2849 comp.dirs.local_cache.path orelse ".", fs.path.sep, tmp_dir_sub_path, err,
28562850 });
28572851 };
28582852 }
......@@ -3419,13 +3413,13 @@ fn renameTmpIntoCache(
34193413 .windows => {
34203414 if (seen_eaccess) return error.AccessDenied;
34213415 seen_eaccess = true;
3422 try cache_directory.handle.deleteTree(o_sub_path);
3416 try cache_directory.handle.deleteTree(io, o_sub_path);
34233417 continue;
34243418 },
34253419 else => return error.AccessDenied,
34263420 },
34273421 error.PathAlreadyExists => {
3428 try cache_directory.handle.deleteTree(o_sub_path);
3422 try cache_directory.handle.deleteTree(io, o_sub_path);
34293423 continue;
34303424 },
34313425 error.FileNotFound => {
src/Package/Fetch.zig+5-3
......@@ -656,9 +656,11 @@ fn checkBuildFileExistence(f: *Fetch) RunError!void {
656656
657657/// This function populates `f.manifest` or leaves it `null`.
658658fn loadManifest(f: *Fetch, pkg_root: Cache.Path) RunError!void {
659 const io = f.job_queue.io;
659660 const eb = &f.error_bundle;
660661 const arena = f.arena.allocator();
661662 const manifest_bytes = pkg_root.root_dir.handle.readFileAllocOptions(
663 io,
662664 try fs.path.join(arena, &.{ pkg_root.sub_path, Manifest.basename }),
663665 arena,
664666 .limited(Manifest.max_bytes),
......@@ -1409,7 +1411,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
14091411 }
14101412 }
14111413
1412 try out_dir.deleteTree(".git");
1414 try out_dir.deleteTree(io, ".git");
14131415 return res;
14141416}
14151417
......@@ -1461,7 +1463,7 @@ pub fn renameTmpIntoCache(io: Io, cache_dir: Io.Dir, tmp_dir_sub_path: []const u
14611463 cache_dir.rename(tmp_dir_sub_path, cache_dir, dest_dir_sub_path, io) catch |err| switch (err) {
14621464 error.FileNotFound => {
14631465 if (handled_missing_dir) return err;
1464 cache_dir.makeDir(dest_dir_sub_path[0..1]) catch |mkd_err| switch (mkd_err) {
1466 cache_dir.makeDir(io, dest_dir_sub_path[0..1], .default_dir) catch |mkd_err| switch (mkd_err) {
14651467 error.PathAlreadyExists => handled_missing_dir = true,
14661468 else => |e| return e,
14671469 };
......@@ -1469,7 +1471,7 @@ pub fn renameTmpIntoCache(io: Io, cache_dir: Io.Dir, tmp_dir_sub_path: []const u
14691471 },
14701472 error.PathAlreadyExists, error.AccessDenied => {
14711473 // Package has been already downloaded and may already be in use on the system.
1472 cache_dir.deleteTree(tmp_dir_sub_path) catch {
1474 cache_dir.deleteTree(io, tmp_dir_sub_path) catch {
14731475 // Garbage files leftover in zig-cache/tmp/ is, as they say
14741476 // on Star Trek, "operating within normal parameters".
14751477 };
src/Package/Fetch/git.zig+2-2
......@@ -253,7 +253,7 @@ pub const Repository = struct {
253253 while (try tree_iter.next()) |entry| {
254254 switch (entry.type) {
255255 .directory => {
256 try dir.makeDir(entry.name);
256 try dir.makeDir(io, entry.name, .default_dir);
257257 var subdir = try dir.openDir(io, entry.name, .{});
258258 defer subdir.close(io);
259259 const sub_path = try std.fs.path.join(repository.odb.allocator, &.{ current_path, entry.name });
......@@ -296,7 +296,7 @@ pub const Repository = struct {
296296 .gitlink => {
297297 // Consistent with git archive behavior, create the directory but
298298 // do nothing else
299 try dir.makeDir(entry.name);
299 try dir.makeDir(io, entry.name, .default_dir);
300300 },
301301 }
302302 }
src/main.zig+1
......@@ -7316,6 +7316,7 @@ fn loadManifest(
73167316) !struct { Package.Manifest, Ast } {
73177317 const manifest_bytes = while (true) {
73187318 break options.dir.readFileAllocOptions(
7319 io,
73197320 Package.Manifest.basename,
73207321 arena,
73217322 .limited(Package.Manifest.max_bytes),
test/src/Cases.zig+3-1
......@@ -10,6 +10,7 @@ const ArrayList = std.ArrayList;
1010
1111gpa: Allocator,
1212arena: Allocator,
13io: Io,
1314cases: std.array_list.Managed(Case),
1415
1516pub const IncrementalCase = struct {
......@@ -334,6 +335,7 @@ fn addFromDirInner(
334335 current_file: *[]const u8,
335336 b: *std.Build,
336337) !void {
338 const io = ctx.io;
337339 var it = try iterable_dir.walk(ctx.arena);
338340 var filenames: ArrayList([]const u8) = .empty;
339341
......@@ -349,7 +351,7 @@ fn addFromDirInner(
349351 current_file.* = filename;
350352
351353 const max_file_size = 10 * 1024 * 1024;
352 const src = try iterable_dir.readFileAllocOptions(filename, ctx.arena, .limited(max_file_size), .@"1", 0);
354 const src = try iterable_dir.readFileAllocOptions(io, filename, ctx.arena, .limited(max_file_size), .@"1", 0);
353355
354356 // Parse the manifest
355357 var manifest = try TestManifest.parse(ctx.arena, src);
test/standalone/posix/relpaths.zig+11-10
......@@ -5,13 +5,14 @@ const builtin = @import("builtin");
55
66const std = @import("std");
77const Io = std.Io;
8const Allocator = std.mem.Allocator;
89
910pub fn main() !void {
1011 if (builtin.target.os.tag == .wasi) return; // Can link, but can't change into tmpDir
1112
12 var Allocator = std.heap.DebugAllocator(.{}){};
13 const a = Allocator.allocator();
14 defer std.debug.assert(Allocator.deinit() == .ok);
13 var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
14 const gpa = debug_allocator.allocator();
15 defer std.debug.assert(debug_allocator.deinit() == .ok);
1516
1617 var threaded: std.Io.Threaded = .init_single_threaded;
1718 const io = threaded.io();
......@@ -24,22 +25,22 @@ pub fn main() !void {
2425 // Want to test relative paths, so cd into the tmpdir for these tests
2526 try tmp.dir.setAsCwd();
2627
27 try test_symlink(a, tmp);
28 try test_symlink(gpa, io, tmp);
2829 try test_link(io, tmp);
2930}
3031
31fn test_symlink(a: std.mem.Allocator, tmp: std.testing.TmpDir) !void {
32fn test_symlink(gpa: Allocator, io: Io, tmp: std.testing.TmpDir) !void {
3233 const target_name = "symlink-target";
3334 const symlink_name = "symlinker";
3435
3536 // Create the target file
36 try tmp.dir.writeFile(.{ .sub_path = target_name, .data = "nonsense" });
37 try tmp.dir.writeFile(io, .{ .sub_path = target_name, .data = "nonsense" });
3738
3839 if (builtin.target.os.tag == .windows) {
39 const wtarget_name = try std.unicode.wtf8ToWtf16LeAllocZ(a, target_name);
40 const wsymlink_name = try std.unicode.wtf8ToWtf16LeAllocZ(a, symlink_name);
41 defer a.free(wtarget_name);
42 defer a.free(wsymlink_name);
40 const wtarget_name = try std.unicode.wtf8ToWtf16LeAllocZ(gpa, target_name);
41 const wsymlink_name = try std.unicode.wtf8ToWtf16LeAllocZ(gpa, symlink_name);
42 defer gpa.free(wtarget_name);
43 defer gpa.free(wsymlink_name);
4344
4445 std.os.windows.CreateSymbolicLink(tmp.dir.fd, wsymlink_name, wtarget_name, false) catch |err| switch (err) {
4546 // Symlink requires admin privileges on windows, so this test can legitimately fail.
test/standalone/windows_bat_args/fuzz.zig+7-4
......@@ -9,6 +9,9 @@ pub fn main() anyerror!void {
99 defer std.debug.assert(debug_alloc_inst.deinit() == .ok);
1010 const gpa = debug_alloc_inst.allocator();
1111
12 var threaded: Io.Threaded = .init(gpa);
13 const io = threaded.io();
14
1215 var it = try std.process.argsWithAllocator(gpa);
1316 defer it.deinit();
1417 _ = it.next() orelse unreachable; // skip binary name
......@@ -58,15 +61,15 @@ pub fn main() anyerror!void {
5861 const preamble_len = buf.items.len;
5962
6063 try buf.appendSlice(gpa, " %*");
61 try tmp.dir.writeFile(.{ .sub_path = "args1.bat", .data = buf.items });
64 try tmp.dir.writeFile(io, .{ .sub_path = "args1.bat", .data = buf.items });
6265 buf.shrinkRetainingCapacity(preamble_len);
6366
6467 try buf.appendSlice(gpa, " %1 %2 %3 %4 %5 %6 %7 %8 %9");
65 try tmp.dir.writeFile(.{ .sub_path = "args2.bat", .data = buf.items });
68 try tmp.dir.writeFile(io, .{ .sub_path = "args2.bat", .data = buf.items });
6669 buf.shrinkRetainingCapacity(preamble_len);
6770
6871 try buf.appendSlice(gpa, " \"%~1\" \"%~2\" \"%~3\" \"%~4\" \"%~5\" \"%~6\" \"%~7\" \"%~8\" \"%~9\"");
69 try tmp.dir.writeFile(.{ .sub_path = "args3.bat", .data = buf.items });
72 try tmp.dir.writeFile(io, .{ .sub_path = "args3.bat", .data = buf.items });
7073 buf.shrinkRetainingCapacity(preamble_len);
7174
7275 var i: u64 = 0;
......@@ -74,7 +77,7 @@ pub fn main() anyerror!void {
7477 const rand_arg = try randomArg(gpa, rand);
7578 defer gpa.free(rand_arg);
7679
77 try testExec(gpa, &.{rand_arg}, null);
80 try testExec(gpa, io, &.{rand_arg}, null);
7881
7982 i += 1;
8083 }
test/standalone/windows_bat_args/test.zig+6-3
......@@ -7,6 +7,9 @@ pub fn main() anyerror!void {
77 defer std.debug.assert(debug_alloc_inst.deinit() == .ok);
88 const gpa = debug_alloc_inst.allocator();
99
10 var threaded: Io.Threaded = .init(gpa);
11 const io = threaded.io();
12
1013 var it = try std.process.argsWithAllocator(gpa);
1114 defer it.deinit();
1215 _ = it.next() orelse unreachable; // skip binary name
......@@ -32,15 +35,15 @@ pub fn main() anyerror!void {
3235 const preamble_len = buf.items.len;
3336
3437 try buf.appendSlice(gpa, " %*");
35 try tmp.dir.writeFile(.{ .sub_path = "args1.bat", .data = buf.items });
38 try tmp.dir.writeFile(io, .{ .sub_path = "args1.bat", .data = buf.items });
3639 buf.shrinkRetainingCapacity(preamble_len);
3740
3841 try buf.appendSlice(gpa, " %1 %2 %3 %4 %5 %6 %7 %8 %9");
39 try tmp.dir.writeFile(.{ .sub_path = "args2.bat", .data = buf.items });
42 try tmp.dir.writeFile(io, .{ .sub_path = "args2.bat", .data = buf.items });
4043 buf.shrinkRetainingCapacity(preamble_len);
4144
4245 try buf.appendSlice(gpa, " \"%~1\" \"%~2\" \"%~3\" \"%~4\" \"%~5\" \"%~6\" \"%~7\" \"%~8\" \"%~9\"");
43 try tmp.dir.writeFile(.{ .sub_path = "args3.bat", .data = buf.items });
46 try tmp.dir.writeFile(io, .{ .sub_path = "args3.bat", .data = buf.items });
4447 buf.shrinkRetainingCapacity(preamble_len);
4548
4649 // Test cases are from https://github.com/rust-lang/rust/blob/master/tests/ui/std/windows-bat-args.rs
test/standalone/windows_spawn/main.zig+4-4
......@@ -65,9 +65,9 @@ pub fn main() anyerror!void {
6565 try std.testing.expectError(error.FileNotFound, testExecWithCwd(gpa, io, "hello.exe", "missing_dir", ""));
6666
6767 // now add a .bat
68 try tmp.dir.writeFile(.{ .sub_path = "hello.bat", .data = "@echo hello from bat" });
68 try tmp.dir.writeFile(io, .{ .sub_path = "hello.bat", .data = "@echo hello from bat" });
6969 // and a .cmd
70 try tmp.dir.writeFile(.{ .sub_path = "hello.cmd", .data = "@echo hello from cmd" });
70 try tmp.dir.writeFile(io, .{ .sub_path = "hello.cmd", .data = "@echo hello from cmd" });
7171
7272 // with extension should find the .bat (case insensitive)
7373 try testExec(gpa, "heLLo.bat", "hello from bat\r\n");
......@@ -84,7 +84,7 @@ pub fn main() anyerror!void {
8484 // without extension should succeed (case insensitive)
8585 try testExec(gpa, "heLLo", "hello from exe\n");
8686
87 try tmp.dir.makeDir("something");
87 try tmp.dir.makeDir(io, "something", .default_dir);
8888 try renameExe(tmp.dir, "hello", "something/hello.exe");
8989
9090 const relative_path_no_ext = try std.fs.path.join(gpa, &.{ tmp_relative_path, "something/hello" });
......@@ -99,7 +99,7 @@ pub fn main() anyerror!void {
9999 try testExec(gpa, "heLLo", "hello from bat\r\n");
100100
101101 // Add a hello.exe that is not a valid executable
102 try tmp.dir.writeFile(.{ .sub_path = "hello.exe", .data = "invalid" });
102 try tmp.dir.writeFile(io, .{ .sub_path = "hello.exe", .data = "invalid" });
103103
104104 // Trying to execute it with extension will give InvalidExe. This is a special
105105 // case for .EXE extensions, where if they ever try to get executed but they are
test/tests.zig+4-4
......@@ -2135,12 +2135,12 @@ pub fn addCliTests(b: *std.Build) *Step {
21352135
21362136 var dir = std.Io.Dir.cwd().openDir(io, tmp_path, .{}) catch @panic("unhandled");
21372137 defer dir.close(io);
2138 dir.writeFile(.{ .sub_path = "fmt1.zig", .data = unformatted_code }) catch @panic("unhandled");
2139 dir.writeFile(.{ .sub_path = "fmt2.zig", .data = unformatted_code }) catch @panic("unhandled");
2140 dir.makeDir("subdir") catch @panic("unhandled");
2138 dir.writeFile(io, .{ .sub_path = "fmt1.zig", .data = unformatted_code }) catch @panic("unhandled");
2139 dir.writeFile(io, .{ .sub_path = "fmt2.zig", .data = unformatted_code }) catch @panic("unhandled");
2140 dir.makeDir(io, "subdir", .default_dir) catch @panic("unhandled");
21412141 var subdir = dir.openDir(io, "subdir", .{}) catch @panic("unhandled");
21422142 defer subdir.close(io);
2143 subdir.writeFile(.{ .sub_path = "fmt3.zig", .data = unformatted_code }) catch @panic("unhandled");
2143 subdir.writeFile(io, .{ .sub_path = "fmt3.zig", .data = unformatted_code }) catch @panic("unhandled");
21442144
21452145 // Test zig fmt affecting only the appropriate files.
21462146 const run1 = b.addSystemCommand(&.{ b.graph.zig_exe, "fmt", "fmt1.zig" });