authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-19 16:21:54-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:11-08:00
log6e0c7ed8659d9d60a59a9dcddd3aed9cd18b659b
tree637d71ea08261d2483f33de3847d43af01bafbcc
parent52ba2a4c72cee39292d09506655197811feceede

std: rename makeDir to createDir for consistency with createFile


6 files changed, 44 insertions(+), 44 deletions(-)

lib/std/Io/Dir.zig+6-6
......@@ -664,25 +664,25 @@ pub const MakeError = error{
664664///
665665/// Related:
666666/// * `makePath`
667/// * `makeDirAbsolute`
668pub fn makeDir(dir: Dir, io: Io, sub_path: []const u8, permissions: Permissions) MakeError!void {
667/// * `createDirAbsolute`
668pub fn createDir(dir: Dir, io: Io, sub_path: []const u8, permissions: Permissions) MakeError!void {
669669 return io.vtable.dirMake(io.userdata, dir, sub_path, permissions);
670670}
671671
672672/// Create a new directory, based on an absolute path.
673673///
674/// Asserts that the path is absolute. See `makeDir` for a function that
674/// Asserts that the path is absolute. See `createDir` for a function that
675675/// operates on both absolute and relative paths.
676676///
677677/// On Windows, `absolute_path` should be encoded as [WTF-8](https://wtf-8.codeberg.page/).
678678/// On WASI, `absolute_path` should be encoded as valid UTF-8.
679679/// On other platforms, `absolute_path` is an opaque sequence of bytes with no particular encoding.
680pub fn makeDirAbsolute(io: Io, absolute_path: []const u8, permissions: Permissions) MakeError!void {
680pub fn createDirAbsolute(io: Io, absolute_path: []const u8, permissions: Permissions) MakeError!void {
681681 assert(path.isAbsolute(absolute_path));
682 return makeDir(.cwd(), io, absolute_path, permissions);
682 return createDir(.cwd(), io, absolute_path, permissions);
683683}
684684
685test makeDirAbsolute {}
685test createDirAbsolute {}
686686
687687pub const MakePathError = MakeError || StatFileError;
688688
lib/std/fs/test.zig+33-33
......@@ -209,7 +209,7 @@ test "Dir.readLink" {
209209 const file_target_path = try ctx.transformPath("file.txt");
210210 try ctx.dir.writeFile(io, .{ .sub_path = file_target_path, .data = "nonsense" });
211211 const dir_target_path = try ctx.transformPath("subdir");
212 try ctx.dir.makeDir(io, dir_target_path, .default_dir);
212 try ctx.dir.createDir(io, dir_target_path, .default_dir);
213213
214214 // On Windows, symlink targets always use the canonical path separator
215215 const canonical_file_target_path = try ctx.toCanonicalPathSep(file_target_path);
......@@ -241,7 +241,7 @@ test "Dir.readLink on non-symlinks" {
241241 const file_path = try ctx.transformPath("file.txt");
242242 try ctx.dir.writeFile(io, .{ .sub_path = file_path, .data = "nonsense" });
243243 const dir_path = try ctx.transformPath("subdir");
244 try ctx.dir.makeDir(io, dir_path, .default_dir);
244 try ctx.dir.createDir(io, dir_path, .default_dir);
245245
246246 // file
247247 var buffer: [Dir.max_path_bytes]u8 = undefined;
......@@ -278,7 +278,7 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {
278278 try testWithAllSupportedPathTypes(struct {
279279 fn impl(ctx: *TestContext) !void {
280280 const dir_target_path = try ctx.transformPath("subdir");
281 try ctx.dir.makeDir(io, dir_target_path, .default_dir);
281 try ctx.dir.createDir(io, dir_target_path, .default_dir);
282282
283283 try setupSymlink(io, ctx.dir, dir_target_path, "symlink", .{ .is_directory = true });
284284
......@@ -301,7 +301,7 @@ test "openDir" {
301301 fn impl(ctx: *TestContext) !void {
302302 const allocator = ctx.arena.allocator();
303303 const subdir_path = try ctx.transformPath("subdir");
304 try ctx.dir.makeDir(io, subdir_path, .default_dir);
304 try ctx.dir.createDir(io, subdir_path, .default_dir);
305305
306306 for ([_][]const u8{ "", ".", ".." }) |sub_path| {
307307 const dir_path = try Dir.path.join(allocator, &.{ subdir_path, sub_path });
......@@ -340,7 +340,7 @@ test "openDirAbsolute" {
340340
341341 const tmp_ino = (try tmp.dir.stat(io)).inode;
342342
343 try tmp.dir.makeDir(io, "subdir", .default_dir);
343 try tmp.dir.createDir(io, "subdir", .default_dir);
344344 const sub_path = try tmp.dir.realPathFileAlloc(io, "subdir", gpa);
345345 defer gpa.free(sub_path);
346346
......@@ -437,7 +437,7 @@ test "readLinkAbsolute" {
437437
438438 // Create some targets
439439 try tmp.dir.writeFile(io, .{ .sub_path = "file.txt", .data = "nonsense" });
440 try tmp.dir.makeDir(io, "subdir", .default_dir);
440 try tmp.dir.createDir(io, "subdir", .default_dir);
441441
442442 // Get base abs path
443443 var arena_allocator = ArenaAllocator.init(testing.allocator);
......@@ -474,7 +474,7 @@ test "Dir.Iterator" {
474474 const file = try tmp_dir.dir.createFile(io, "some_file", .{});
475475 file.close(io);
476476
477 try tmp_dir.dir.makeDir(io, "some_dir", .default_dir);
477 try tmp_dir.dir.createDir(io, "some_dir", .default_dir);
478478
479479 var arena = ArenaAllocator.init(testing.allocator);
480480 defer arena.deinit();
......@@ -543,7 +543,7 @@ test "Dir.Iterator twice" {
543543 const file = try tmp_dir.dir.createFile(io, "some_file", .{});
544544 file.close(io);
545545
546 try tmp_dir.dir.makeDir(io, "some_dir", .default_dir);
546 try tmp_dir.dir.createDir(io, "some_dir", .default_dir);
547547
548548 var arena = ArenaAllocator.init(testing.allocator);
549549 defer arena.deinit();
......@@ -578,7 +578,7 @@ test "Dir.Iterator reset" {
578578 const file = try tmp_dir.dir.createFile(io, "some_file", .{});
579579 file.close(io);
580580
581 try tmp_dir.dir.makeDir(io, "some_dir", .default_dir);
581 try tmp_dir.dir.createDir(io, "some_dir", .default_dir);
582582
583583 var arena = ArenaAllocator.init(testing.allocator);
584584 defer arena.deinit();
......@@ -662,7 +662,7 @@ test "Dir.realPath smoke test" {
662662
663663 // Now create the file and dir
664664 try ctx.dir.writeFile(io, .{ .sub_path = test_file_path, .data = "" });
665 try ctx.dir.makeDir(io, test_dir_path, .default_dir);
665 try ctx.dir.createDir(io, test_dir_path, .default_dir);
666666
667667 const base_path = try ctx.transformPath(".");
668668 const base_realpath = try ctx.dir.realPathFileAlloc(io, base_path, arena);
......@@ -754,7 +754,7 @@ test "Dir.statFile" {
754754
755755 try expectError(error.FileNotFound, ctx.dir.statFile(io, test_dir_name, .{}));
756756
757 try ctx.dir.makeDir(io, test_dir_name, .default_dir);
757 try ctx.dir.createDir(io, test_dir_name, .default_dir);
758758
759759 const stat = try ctx.dir.statFile(io, test_dir_name, .{});
760760 try expectEqual(.directory, stat.kind);
......@@ -787,12 +787,12 @@ test "directory operations on files" {
787787 var file = try ctx.dir.createFile(io, test_file_name, .{ .read = true });
788788 file.close(io);
789789
790 try expectError(error.PathAlreadyExists, ctx.dir.makeDir(io, test_file_name, .default_dir));
790 try expectError(error.PathAlreadyExists, ctx.dir.createDir(io, test_file_name, .default_dir));
791791 try expectError(error.NotDir, ctx.dir.openDir(io, test_file_name, .{}));
792792 try expectError(error.NotDir, ctx.dir.deleteDir(io, test_file_name));
793793
794794 if (ctx.path_type == .absolute and comptime PathType.absolute.isSupported(builtin.os)) {
795 try expectError(error.PathAlreadyExists, Dir.makeDirAbsolute(io, test_file_name, .default_dir));
795 try expectError(error.PathAlreadyExists, Dir.createDirAbsolute(io, test_file_name, .default_dir));
796796 try expectError(error.NotDir, Dir.deleteDirAbsolute(io, test_file_name));
797797 }
798798
......@@ -815,7 +815,7 @@ test "file operations on directories" {
815815 fn impl(ctx: *TestContext) !void {
816816 const test_dir_name = try ctx.transformPath("test_dir");
817817
818 try ctx.dir.makeDir(io, test_dir_name, .default_dir);
818 try ctx.dir.createDir(io, test_dir_name, .default_dir);
819819
820820 try expectError(error.IsDir, ctx.dir.createFile(io, test_dir_name, .{}));
821821 try expectError(error.IsDir, ctx.dir.deleteFile(io, test_dir_name));
......@@ -887,7 +887,7 @@ test "deleteDir" {
887887 try expectError(error.FileNotFound, ctx.dir.deleteDir(io, test_dir_path));
888888
889889 // deleting a non-empty directory
890 try ctx.dir.makeDir(io, test_dir_path, .default_dir);
890 try ctx.dir.createDir(io, test_dir_path, .default_dir);
891891 try ctx.dir.writeFile(io, .{ .sub_path = test_file_path, .data = "" });
892892 try expectError(error.DirNotEmpty, ctx.dir.deleteDir(io, test_dir_path));
893893
......@@ -956,7 +956,7 @@ test "Dir.rename directories" {
956956 const test_dir_renamed_path = try ctx.transformPath("test_dir_renamed");
957957
958958 // Renaming directories
959 try ctx.dir.makeDir(io, test_dir_path, .default_dir);
959 try ctx.dir.createDir(io, test_dir_path, .default_dir);
960960 try ctx.dir.rename(test_dir_path, ctx.dir, test_dir_renamed_path, io);
961961
962962 // Ensure the directory was renamed
......@@ -992,8 +992,8 @@ test "Dir.rename directory onto empty dir" {
992992 const test_dir_path = try ctx.transformPath("test_dir");
993993 const target_dir_path = try ctx.transformPath("target_dir_path");
994994
995 try ctx.dir.makeDir(io, test_dir_path, .default_dir);
996 try ctx.dir.makeDir(io, target_dir_path, .default_dir);
995 try ctx.dir.createDir(io, test_dir_path, .default_dir);
996 try ctx.dir.createDir(io, target_dir_path, .default_dir);
997997 try ctx.dir.rename(test_dir_path, ctx.dir, target_dir_path, io);
998998
999999 // Ensure the directory was renamed
......@@ -1014,7 +1014,7 @@ test "Dir.rename directory onto non-empty dir" {
10141014 const test_dir_path = try ctx.transformPath("test_dir");
10151015 const target_dir_path = try ctx.transformPath("target_dir_path");
10161016
1017 try ctx.dir.makeDir(io, test_dir_path, .default_dir);
1017 try ctx.dir.createDir(io, test_dir_path, .default_dir);
10181018
10191019 var target_dir = try ctx.dir.makeOpenPath(io, target_dir_path, .{});
10201020 var file = try target_dir.createFile(io, "test_file", .{ .read = true });
......@@ -1043,7 +1043,7 @@ test "Dir.rename file <-> dir" {
10431043
10441044 var file = try ctx.dir.createFile(io, test_file_path, .{ .read = true });
10451045 file.close(io);
1046 try ctx.dir.makeDir(io, test_dir_path, .default_dir);
1046 try ctx.dir.createDir(io, test_dir_path, .default_dir);
10471047 try expectError(error.IsDir, ctx.dir.rename(test_file_path, ctx.dir, test_dir_path, io));
10481048 try expectError(error.NotDir, ctx.dir.rename(test_dir_path, ctx.dir, test_file_path, io));
10491049 }
......@@ -1115,7 +1115,7 @@ test "renameAbsolute" {
11151115 // Renaming directories
11161116 const test_dir_name = "test_dir";
11171117 const renamed_test_dir_name = "test_dir_renamed";
1118 try tmp_dir.dir.makeDir(io, test_dir_name, .default_dir);
1118 try tmp_dir.dir.createDir(io, test_dir_name, .default_dir);
11191119 try Dir.renameAbsolute(
11201120 try Dir.path.join(allocator, &.{ base_path, test_dir_name }),
11211121 try Dir.path.join(allocator, &.{ base_path, renamed_test_dir_name }),
......@@ -1256,7 +1256,7 @@ test "makePath but sub_path contains pre-existing file" {
12561256 var tmp = tmpDir(.{});
12571257 defer tmp.cleanup();
12581258
1259 try tmp.dir.makeDir(io, "foo", .default_dir);
1259 try tmp.dir.createDir(io, "foo", .default_dir);
12601260 try tmp.dir.writeFile(io, .{ .sub_path = "foo/bar", .data = "" });
12611261
12621262 try expectError(error.NotDir, tmp.dir.makePath(io, "foo/bar/baz"));
......@@ -1273,10 +1273,10 @@ test "makepath existing directories" {
12731273 var tmp = tmpDir(.{});
12741274 defer tmp.cleanup();
12751275
1276 try tmp.dir.makeDir(io, "A", .default_dir);
1276 try tmp.dir.createDir(io, "A", .default_dir);
12771277 var tmpA = try tmp.dir.openDir(io, "A", .{});
12781278 defer tmpA.close(io);
1279 try tmpA.makeDir(io, "B", .default_dir);
1279 try tmpA.createDir(io, "B", .default_dir);
12801280
12811281 const testPath = "A" ++ Dir.path.sep_str ++ "B" ++ Dir.path.sep_str ++ "C";
12821282 try tmp.dir.makePath(io, testPath);
......@@ -1290,7 +1290,7 @@ test "makepath through existing valid symlink" {
12901290 var tmp = tmpDir(.{});
12911291 defer tmp.cleanup();
12921292
1293 try tmp.dir.makeDir(io, "realfolder", .default_dir);
1293 try tmp.dir.createDir(io, "realfolder", .default_dir);
12941294 try setupSymlink(io, tmp.dir, "." ++ Dir.path.sep_str ++ "realfolder", "working-symlink", .{});
12951295
12961296 try tmp.dir.makePath(io, "working-symlink" ++ Dir.path.sep_str ++ "in-realfolder");
......@@ -1985,7 +1985,7 @@ test "'.' and '..' in Dir functions" {
19851985 const rename_path = try ctx.transformPath("./subdir/../rename");
19861986 const update_path = try ctx.transformPath("./subdir/../update");
19871987
1988 try ctx.dir.makeDir(io, subdir_path, .default_dir);
1988 try ctx.dir.createDir(io, subdir_path, .default_dir);
19891989 try ctx.dir.access(io, subdir_path, .{});
19901990 var created_subdir = try ctx.dir.openDir(io, subdir_path, .{});
19911991 created_subdir.close(io);
......@@ -2026,7 +2026,7 @@ test "'.' and '..' in absolute functions" {
20262026 const base_path = try tmp.dir.realPathFileAlloc(io, ".", allocator);
20272027
20282028 const subdir_path = try Dir.path.join(allocator, &.{ base_path, "./subdir" });
2029 try Dir.makeDirAbsolute(io, subdir_path, .default_dir);
2029 try Dir.createDirAbsolute(io, subdir_path, .default_dir);
20302030 try Dir.accessAbsolute(io, subdir_path, .{});
20312031 var created_subdir = try Dir.openDirAbsolute(io, subdir_path, .{});
20322032 created_subdir.close(io);
......@@ -2062,7 +2062,7 @@ test "chmod" {
20622062 try file.setPermissions(io, .fromMode(0o644));
20632063 try expectEqual(0o644, (try file.stat(io)).permissions.toMode() & 0o7777);
20642064
2065 try tmp.dir.makeDir(io, "test_dir", .default_dir);
2065 try tmp.dir.createDir(io, "test_dir", .default_dir);
20662066 var dir = try tmp.dir.openDir(io, "test_dir", .{ .iterate = true });
20672067 defer dir.close(io);
20682068
......@@ -2083,7 +2083,7 @@ test "change ownership" {
20832083 defer file.close(io);
20842084 try file.setOwner(io, null, null);
20852085
2086 try tmp.dir.makeDir(io, "test_dir", .default_dir);
2086 try tmp.dir.createDir(io, "test_dir", .default_dir);
20872087
20882088 var dir = try tmp.dir.openDir(io, "test_dir", .{ .iterate = true });
20892089 defer dir.close(io);
......@@ -2107,7 +2107,7 @@ test "invalid UTF-8/WTF-8 paths" {
21072107
21082108 try expectError(expected_err, ctx.dir.createFile(io, invalid_path, .{}));
21092109
2110 try expectError(expected_err, ctx.dir.makeDir(io, invalid_path, .default_dir));
2110 try expectError(expected_err, ctx.dir.createDir(io, invalid_path, .default_dir));
21112111
21122112 try expectError(expected_err, ctx.dir.makePath(io, invalid_path));
21132113 try expectError(expected_err, ctx.dir.makeOpenPath(io, invalid_path, .{}));
......@@ -2150,7 +2150,7 @@ test "invalid UTF-8/WTF-8 paths" {
21502150 if (native_os != .wasi and ctx.path_type != .relative) {
21512151 var buf: [Dir.max_path_bytes]u8 = undefined;
21522152 try expectError(expected_err, Dir.copyFileAbsolute(invalid_path, invalid_path, io, .{}));
2153 try expectError(expected_err, Dir.makeDirAbsolute(io, invalid_path, .default_dir));
2153 try expectError(expected_err, Dir.createDirAbsolute(io, invalid_path, .default_dir));
21542154 try expectError(expected_err, Dir.deleteDirAbsolute(io, invalid_path));
21552155 try expectError(expected_err, Dir.renameAbsolute(invalid_path, invalid_path, io));
21562156 try expectError(expected_err, Dir.openDirAbsolute(io, invalid_path, .{}));
......@@ -2496,7 +2496,7 @@ test "access smoke test" {
24962496
24972497 {
24982498 // Create some directory
2499 try tmp.dir.makeDir(io, "some_dir", .default_dir);
2499 try tmp.dir.createDir(io, "some_dir", .default_dir);
25002500 }
25012501
25022502 {
......@@ -2552,7 +2552,7 @@ test "open smoke test" {
25522552 }
25532553
25542554 try expectError(error.NotDir, tmp.dir.openDir(io, "some_file", .{}));
2555 try tmp.dir.makeDir(io, "some_dir", .default_dir);
2555 try tmp.dir.createDir(io, "some_dir", .default_dir);
25562556
25572557 {
25582558 const dir = try tmp.dir.openDir(io, "some_dir", .{});
src/Package/Fetch.zig+1-1
......@@ -1458,7 +1458,7 @@ pub fn renameTmpIntoCache(io: Io, cache_dir: Io.Dir, tmp_dir_sub_path: []const u
14581458 cache_dir.rename(tmp_dir_sub_path, cache_dir, dest_dir_sub_path, io) catch |err| switch (err) {
14591459 error.FileNotFound => {
14601460 if (handled_missing_dir) return err;
1461 cache_dir.makeDir(io, dest_dir_sub_path[0..1], .default_dir) catch |mkd_err| switch (mkd_err) {
1461 cache_dir.createDir(io, dest_dir_sub_path[0..1], .default_dir) catch |mkd_err| switch (mkd_err) {
14621462 error.PathAlreadyExists => handled_missing_dir = true,
14631463 else => |e| return e,
14641464 };
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(io, entry.name, .default_dir);
256 try dir.createDir(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(io, entry.name, .default_dir);
299 try dir.createDir(io, entry.name, .default_dir);
300300 },
301301 }
302302 }
test/standalone/windows_spawn/main.zig+1-1
......@@ -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(io, "something", .default_dir);
87 try tmp.dir.createDir(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" });
test/tests.zig+1-1
......@@ -2137,7 +2137,7 @@ pub fn addCliTests(b: *std.Build) *Step {
21372137 defer dir.close(io);
21382138 dir.writeFile(io, .{ .sub_path = "fmt1.zig", .data = unformatted_code }) catch @panic("unhandled");
21392139 dir.writeFile(io, .{ .sub_path = "fmt2.zig", .data = unformatted_code }) catch @panic("unhandled");
2140 dir.makeDir(io, "subdir", .default_dir) catch @panic("unhandled");
2140 dir.createDir(io, "subdir", .default_dir) catch @panic("unhandled");
21412141 var subdir = dir.openDir(io, "subdir", .{}) catch @panic("unhandled");
21422142 defer subdir.close(io);
21432143 subdir.writeFile(io, .{ .sub_path = "fmt3.zig", .data = unformatted_code }) catch @panic("unhandled");