authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2024-05-02 20:54:48-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-03 13:29:22-07:00
logb86c4bde64b2c0d01e4d582798ac1b84dd50b99b
tree1e58edebb2bac2b4a7bee4e5d663ea5cb0cbf248
parenta52f12afc97c5973cfb844be01cf40a9a6fdb57a

Rename Dir.writeFile2 -> Dir.writeFile and update all callsites

writeFile was deprecated in favor of writeFile2 in f645022d16361865e24582d28f1e62312fbc73bb. This commit renames writeFile2 to writeFile and makes writeFile2 a compile error.

23 files changed, 83 insertions(+), 82 deletions(-)

lib/compiler/build_runner.zig+1-1
......@@ -308,7 +308,7 @@ pub fn main() !void {
308308 }
309309 const s = std.fs.path.sep_str;
310310 const tmp_sub_path = "tmp" ++ s ++ (output_tmp_nonce orelse fatal("missing -Z arg", .{}));
311 local_cache_directory.handle.writeFile2(.{
311 local_cache_directory.handle.writeFile(.{
312312 .sub_path = tmp_sub_path,
313313 .data = buffer.items,
314314 .flags = .{ .exclusive = true },
lib/compiler/reduce.zig+2-2
......@@ -233,7 +233,7 @@ pub fn main() !void {
233233 }
234234 }
235235
236 try std.fs.cwd().writeFile(root_source_file_path, rendered.items);
236 try std.fs.cwd().writeFile(.{ .sub_path = root_source_file_path, .data = rendered.items });
237237 // std.debug.print("trying this code:\n{s}\n", .{rendered.items});
238238
239239 const interestingness = try runCheck(arena, interestingness_argv.items);
......@@ -274,7 +274,7 @@ pub fn main() !void {
274274 fixups.clearRetainingCapacity();
275275 rendered.clearRetainingCapacity();
276276 try tree.renderToArrayList(&rendered, fixups);
277 try std.fs.cwd().writeFile(root_source_file_path, rendered.items);
277 try std.fs.cwd().writeFile(.{ .sub_path = root_source_file_path, .data = rendered.items });
278278
279279 return std.process.cleanExit();
280280 }
lib/compiler/resinator/main.zig+1-1
......@@ -178,7 +178,7 @@ pub fn main() !void {
178178 defer allocator.free(full_input);
179179
180180 if (options.preprocess == .only) {
181 try std.fs.cwd().writeFile(options.output_filename, full_input);
181 try std.fs.cwd().writeFile(.{ .sub_path = options.output_filename, .data = full_input });
182182 return;
183183 }
184184
lib/std/Build/Cache.zig+7-7
......@@ -1005,7 +1005,7 @@ pub fn readSmallFile(dir: fs.Dir, sub_path: []const u8, buffer: []u8) ![]u8 {
10051005pub fn writeSmallFile(dir: fs.Dir, sub_path: []const u8, data: []const u8) !void {
10061006 assert(data.len <= 255);
10071007 if (builtin.os.tag == .windows) {
1008 return dir.writeFile(sub_path, data);
1008 return dir.writeFile(.{ .sub_path = sub_path, .data = data });
10091009 } else {
10101010 return dir.symLink(data, sub_path, .{});
10111011 }
......@@ -1052,7 +1052,7 @@ test "cache file and then recall it" {
10521052 const temp_file = "test.txt";
10531053 const temp_manifest_dir = "temp_manifest_dir";
10541054
1055 try tmp.dir.writeFile(temp_file, "Hello, world!\n");
1055 try tmp.dir.writeFile(.{ .sub_path = temp_file, .data = "Hello, world!\n" });
10561056
10571057 // Wait for file timestamps to tick
10581058 const initial_time = try testGetCurrentFileTimestamp(tmp.dir);
......@@ -1120,7 +1120,7 @@ test "check that changing a file makes cache fail" {
11201120 const original_temp_file_contents = "Hello, world!\n";
11211121 const updated_temp_file_contents = "Hello, world; but updated!\n";
11221122
1123 try tmp.dir.writeFile(temp_file, original_temp_file_contents);
1123 try tmp.dir.writeFile(.{ .sub_path = temp_file, .data = original_temp_file_contents });
11241124
11251125 // Wait for file timestamps to tick
11261126 const initial_time = try testGetCurrentFileTimestamp(tmp.dir);
......@@ -1156,7 +1156,7 @@ test "check that changing a file makes cache fail" {
11561156 try ch.writeManifest();
11571157 }
11581158
1159 try tmp.dir.writeFile(temp_file, updated_temp_file_contents);
1159 try tmp.dir.writeFile(.{ .sub_path = temp_file, .data = updated_temp_file_contents });
11601160
11611161 {
11621162 var ch = cache.obtain();
......@@ -1241,8 +1241,8 @@ test "Manifest with files added after initial hash work" {
12411241 const temp_file2 = "cache_hash_post_file_test2.txt";
12421242 const temp_manifest_dir = "cache_hash_post_file_manifest_dir";
12431243
1244 try tmp.dir.writeFile(temp_file1, "Hello, world!\n");
1245 try tmp.dir.writeFile(temp_file2, "Hello world the second!\n");
1244 try tmp.dir.writeFile(.{ .sub_path = temp_file1, .data = "Hello, world!\n" });
1245 try tmp.dir.writeFile(.{ .sub_path = temp_file2, .data = "Hello world the second!\n" });
12461246
12471247 // Wait for file timestamps to tick
12481248 const initial_time = try testGetCurrentFileTimestamp(tmp.dir);
......@@ -1292,7 +1292,7 @@ test "Manifest with files added after initial hash work" {
12921292 try testing.expect(mem.eql(u8, &digest1, &digest2));
12931293
12941294 // Modify the file added after initial hash
1295 try tmp.dir.writeFile(temp_file2, "Hello world the second, updated\n");
1295 try tmp.dir.writeFile(.{ .sub_path = temp_file2, .data = "Hello world the second, updated\n" });
12961296
12971297 // Wait for file timestamps to tick
12981298 const initial_time2 = try testGetCurrentFileTimestamp(tmp.dir);
lib/std/Build/Step/Compile.zig+1-1
......@@ -1711,7 +1711,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
17111711 );
17121712
17131713 const args_file = "args" ++ fs.path.sep_str ++ args_hex_hash;
1714 try b.cache_root.handle.writeFile(args_file, args);
1714 try b.cache_root.handle.writeFile(.{ .sub_path = args_file, .data = args });
17151715
17161716 const resolved_args_file = try mem.concat(arena, u8, &.{
17171717 "@",
lib/std/Build/Step/ConfigHeader.zig+1-1
......@@ -246,7 +246,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
246246 });
247247 };
248248
249 b.cache_root.handle.writeFile(sub_path, output.items) catch |err| {
249 b.cache_root.handle.writeFile(.{ .sub_path = sub_path, .data = output.items }) catch |err| {
250250 return step.fail("unable to write file '{}{s}': {s}", .{
251251 b.cache_root, sub_path, @errorName(err),
252252 });
lib/std/Build/Step/Options.zig+1-1
......@@ -464,7 +464,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
464464 });
465465 };
466466
467 b.cache_root.handle.writeFile(tmp_sub_path, self.contents.items) catch |err| {
467 b.cache_root.handle.writeFile(.{ .sub_path = tmp_sub_path, .data = self.contents.items }) catch |err| {
468468 return step.fail("unable to write options to '{}{s}': {s}", .{
469469 b.cache_root, tmp_sub_path, @errorName(err),
470470 });
lib/std/Build/Step/Run.zig+1-1
......@@ -930,7 +930,7 @@ fn runCommand(
930930 b.cache_root, sub_path_dirname, @errorName(err),
931931 });
932932 };
933 b.cache_root.handle.writeFile(sub_path, stream.bytes.?) catch |err| {
933 b.cache_root.handle.writeFile(.{ .sub_path = sub_path, .data = stream.bytes.? }) catch |err| {
934934 return step.fail("unable to write file '{}{s}': {s}", .{
935935 b.cache_root, sub_path, @errorName(err),
936936 });
lib/std/Build/Step/WriteFile.zig+2-2
......@@ -218,7 +218,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
218218 }
219219 switch (output_source_file.contents) {
220220 .bytes => |bytes| {
221 b.build_root.handle.writeFile(output_source_file.sub_path, bytes) catch |err| {
221 b.build_root.handle.writeFile(.{ .sub_path = output_source_file.sub_path, .data = bytes }) catch |err| {
222222 return step.fail("unable to write file '{}{s}': {s}", .{
223223 b.build_root, output_source_file.sub_path, @errorName(err),
224224 });
......@@ -311,7 +311,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
311311 }
312312 switch (file.contents) {
313313 .bytes => |bytes| {
314 cache_dir.writeFile(file.sub_path, bytes) catch |err| {
314 cache_dir.writeFile(.{ .sub_path = file.sub_path, .data = bytes }) catch |err| {
315315 return step.fail("unable to write file '{}{s}{c}{s}': {s}", .{
316316 b.cache_root, cache_path, fs.path.sep, file.sub_path, @errorName(err),
317317 });
lib/std/debug.zig+6-3
......@@ -1524,7 +1524,7 @@ test printLineFromFileAnyOs {
15241524 {
15251525 const path = try join(allocator, &.{ test_dir_path, "one_line.zig" });
15261526 defer allocator.free(path);
1527 try test_dir.dir.writeFile("one_line.zig", "no new lines in this file, but one is printed anyway");
1527 try test_dir.dir.writeFile(.{ .sub_path = "one_line.zig", .data = "no new lines in this file, but one is printed anyway" });
15281528
15291529 try expectError(error.EndOfFile, printLineFromFileAnyOs(output_stream, .{ .file_name = path, .line = 2, .column = 0 }));
15301530
......@@ -1535,11 +1535,14 @@ test printLineFromFileAnyOs {
15351535 {
15361536 const path = try fs.path.join(allocator, &.{ test_dir_path, "three_lines.zig" });
15371537 defer allocator.free(path);
1538 try test_dir.dir.writeFile("three_lines.zig",
1538 try test_dir.dir.writeFile(.{
1539 .sub_path = "three_lines.zig",
1540 .data =
15391541 \\1
15401542 \\2
15411543 \\3
1542 );
1544 ,
1545 });
15431546
15441547 try printLineFromFileAnyOs(output_stream, .{ .file_name = path, .line = 1, .column = 0 });
15451548 try expectEqualStrings("1\n", output.items);
lib/std/fs/Dir.zig+3-13
......@@ -2339,18 +2339,6 @@ fn deleteTreeOpenInitialSubpath(self: Dir, sub_path: []const u8, kind_hint: File
23392339
23402340pub const WriteFileError = File.WriteError || File.OpenError;
23412341
2342/// Deprecated: use `writeFile2`.
2343/// On Windows, `sub_path` should be encoded as [WTF-8](https://simonsapin.github.io/wtf-8/).
2344/// On WASI, `sub_path` should be encoded as valid UTF-8.
2345/// On other platforms, `sub_path` is an opaque sequence of bytes with no particular encoding.
2346pub fn writeFile(self: Dir, sub_path: []const u8, data: []const u8) WriteFileError!void {
2347 return writeFile2(self, .{
2348 .sub_path = sub_path,
2349 .data = data,
2350 .flags = .{},
2351 });
2352}
2353
23542342pub const WriteFileOptions = struct {
23552343 /// On Windows, `sub_path` should be encoded as [WTF-8](https://simonsapin.github.io/wtf-8/).
23562344 /// On WASI, `sub_path` should be encoded as valid UTF-8.
......@@ -2361,12 +2349,14 @@ pub const WriteFileOptions = struct {
23612349};
23622350
23632351/// Writes content to the file system, using the file creation flags provided.
2364pub fn writeFile2(self: Dir, options: WriteFileOptions) WriteFileError!void {
2352pub fn writeFile(self: Dir, options: WriteFileOptions) WriteFileError!void {
23652353 var file = try self.createFile(options.sub_path, options.flags);
23662354 defer file.close();
23672355 try file.writeAll(options.data);
23682356}
23692357
2358pub const writeFile2 = @compileError("deprecated; renamed to writeFile");
2359
23702360pub const AccessError = posix.AccessError;
23712361
23722362/// Test accessing `sub_path`.
lib/std/fs/test.zig+28-20
......@@ -178,7 +178,7 @@ test "Dir.readLink" {
178178 fn impl(ctx: *TestContext) !void {
179179 // Create some targets
180180 const file_target_path = try ctx.transformPath("file.txt");
181 try ctx.dir.writeFile(file_target_path, "nonsense");
181 try ctx.dir.writeFile(.{ .sub_path = file_target_path, .data = "nonsense" });
182182 const dir_target_path = try ctx.transformPath("subdir");
183183 try ctx.dir.makeDir(dir_target_path);
184184
......@@ -398,7 +398,7 @@ test "readLinkAbsolute" {
398398 defer tmp.cleanup();
399399
400400 // Create some targets
401 try tmp.dir.writeFile("file.txt", "nonsense");
401 try tmp.dir.writeFile(.{ .sub_path = "file.txt", .data = "nonsense" });
402402 try tmp.dir.makeDir("subdir");
403403
404404 // Get base abs path
......@@ -620,7 +620,7 @@ test "Dir.realpath smoke test" {
620620 try testing.expectError(error.FileNotFound, ctx.dir.realpath(test_dir_path, &buf));
621621
622622 // Now create the file and dir
623 try ctx.dir.writeFile(test_file_path, "");
623 try ctx.dir.writeFile(.{ .sub_path = test_file_path, .data = "" });
624624 try ctx.dir.makeDir(test_dir_path);
625625
626626 const base_path = try ctx.transformPath(".");
......@@ -695,7 +695,7 @@ test "Dir.statFile" {
695695
696696 try testing.expectError(error.FileNotFound, ctx.dir.statFile(test_file_name));
697697
698 try ctx.dir.writeFile(test_file_name, "");
698 try ctx.dir.writeFile(.{ .sub_path = test_file_name, .data = "" });
699699
700700 const stat = try ctx.dir.statFile(test_file_name);
701701 try testing.expectEqual(File.Kind.file, stat.kind);
......@@ -803,7 +803,7 @@ test "deleteDir" {
803803
804804 // deleting a non-empty directory
805805 try ctx.dir.makeDir(test_dir_path);
806 try ctx.dir.writeFile(test_file_path, "");
806 try ctx.dir.writeFile(.{ .sub_path = test_file_path, .data = "" });
807807 try testing.expectError(error.DirNotEmpty, ctx.dir.deleteDir(test_dir_path));
808808
809809 // deleting an empty directory
......@@ -1071,7 +1071,7 @@ test "deleteTree on a symlink" {
10711071 defer tmp.cleanup();
10721072
10731073 // Symlink to a file
1074 try tmp.dir.writeFile("file", "");
1074 try tmp.dir.writeFile(.{ .sub_path = "file", .data = "" });
10751075 try setupSymlink(tmp.dir, "file", "filelink", .{});
10761076
10771077 try tmp.dir.deleteTree("filelink");
......@@ -1094,8 +1094,14 @@ test "makePath, put some files in it, deleteTree" {
10941094 const dir_path = try ctx.transformPath("os_test_tmp");
10951095
10961096 try ctx.dir.makePath(try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c" }));
1097 try ctx.dir.writeFile(try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c", "file.txt" }), "nonsense");
1098 try ctx.dir.writeFile(try fs.path.join(allocator, &.{ "os_test_tmp", "b", "file2.txt" }), "blah");
1097 try ctx.dir.writeFile(.{
1098 .sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c", "file.txt" }),
1099 .data = "nonsense",
1100 });
1101 try ctx.dir.writeFile(.{
1102 .sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "file2.txt" }),
1103 .data = "blah",
1104 });
10991105
11001106 try ctx.dir.deleteTree(dir_path);
11011107 try testing.expectError(error.FileNotFound, ctx.dir.openDir(dir_path, .{}));
......@@ -1110,8 +1116,14 @@ test "makePath, put some files in it, deleteTreeMinStackSize" {
11101116 const dir_path = try ctx.transformPath("os_test_tmp");
11111117
11121118 try ctx.dir.makePath(try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c" }));
1113 try ctx.dir.writeFile(try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c", "file.txt" }), "nonsense");
1114 try ctx.dir.writeFile(try fs.path.join(allocator, &.{ "os_test_tmp", "b", "file2.txt" }), "blah");
1119 try ctx.dir.writeFile(.{
1120 .sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c", "file.txt" }),
1121 .data = "nonsense",
1122 });
1123 try ctx.dir.writeFile(.{
1124 .sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "file2.txt" }),
1125 .data = "blah",
1126 });
11151127
11161128 try ctx.dir.deleteTreeMinStackSize(dir_path);
11171129 try testing.expectError(error.FileNotFound, ctx.dir.openDir(dir_path, .{}));
......@@ -1134,7 +1146,7 @@ test "makePath but sub_path contains pre-existing file" {
11341146 defer tmp.cleanup();
11351147
11361148 try tmp.dir.makeDir("foo");
1137 try tmp.dir.writeFile("foo/bar", "");
1149 try tmp.dir.writeFile(.{ .sub_path = "foo/bar", .data = "" });
11381150
11391151 try testing.expectError(error.NotDir, tmp.dir.makePath("foo/bar/baz"));
11401152}
......@@ -1227,7 +1239,7 @@ fn testFilenameLimits(iterable_dir: Dir, maxed_filename: []const u8) !void {
12271239 var maxed_dir = try iterable_dir.makeOpenPath(maxed_filename, .{});
12281240 defer maxed_dir.close();
12291241
1230 try maxed_dir.writeFile(maxed_filename, "");
1242 try maxed_dir.writeFile(.{ .sub_path = maxed_filename, .data = "" });
12311243
12321244 var walker = try iterable_dir.walk(testing.allocator);
12331245 defer walker.deinit();
......@@ -1357,7 +1369,7 @@ test "access file" {
13571369 try ctx.dir.makePath(dir_path);
13581370 try testing.expectError(error.FileNotFound, ctx.dir.access(file_path, .{}));
13591371
1360 try ctx.dir.writeFile(file_path, "");
1372 try ctx.dir.writeFile(.{ .sub_path = file_path, .data = "" });
13611373 try ctx.dir.access(file_path, .{});
13621374 try ctx.dir.deleteTree(dir_path);
13631375 }
......@@ -1463,7 +1475,7 @@ test "copyFile" {
14631475 const dest_file = try ctx.transformPath("tmp_test_copy_file2.txt");
14641476 const dest_file2 = try ctx.transformPath("tmp_test_copy_file3.txt");
14651477
1466 try ctx.dir.writeFile(src_file, data);
1478 try ctx.dir.writeFile(.{ .sub_path = src_file, .data = data });
14671479 defer ctx.dir.deleteFile(src_file) catch {};
14681480
14691481 try ctx.dir.copyFile(src_file, ctx.dir, dest_file, .{});
......@@ -1740,7 +1752,7 @@ test "'.' and '..' in fs.Dir functions" {
17401752 renamed_file.close();
17411753 try ctx.dir.deleteFile(rename_path);
17421754
1743 try ctx.dir.writeFile(update_path, "something");
1755 try ctx.dir.writeFile(.{ .sub_path = update_path, .data = "something" });
17441756 const prev_status = try ctx.dir.updateFile(file_path, ctx.dir, update_path, .{});
17451757 try testing.expectEqual(fs.Dir.PrevStatus.stale, prev_status);
17461758
......@@ -2009,11 +2021,7 @@ test "invalid UTF-8/WTF-8 paths" {
20092021 try testing.expectError(expected_err, ctx.dir.deleteTree(invalid_path));
20102022 try testing.expectError(expected_err, ctx.dir.deleteTreeMinStackSize(invalid_path));
20112023
2012 try testing.expectError(expected_err, ctx.dir.writeFile(invalid_path, ""));
2013 try testing.expectError(expected_err, ctx.dir.writeFile2(.{
2014 .sub_path = invalid_path,
2015 .data = "",
2016 }));
2024 try testing.expectError(expected_err, ctx.dir.writeFile(.{ .sub_path = invalid_path, .data = "" }));
20172025
20182026 try testing.expectError(expected_err, ctx.dir.access(invalid_path, .{}));
20192027 try testing.expectError(expected_err, ctx.dir.accessZ(invalid_path, .{}));
lib/std/posix/test.zig+5-5
......@@ -209,7 +209,7 @@ test "symlink with relative paths" {
209209 cwd.deleteFile("symlinked") catch {};
210210
211211 // First, try relative paths in cwd
212 try cwd.writeFile("file.txt", "nonsense");
212 try cwd.writeFile(.{ .sub_path = "file.txt", .data = "nonsense" });
213213
214214 if (native_os == .windows) {
215215 std.os.windows.CreateSymbolicLink(
......@@ -268,7 +268,7 @@ test "link with relative paths" {
268268 cwd.deleteFile("example.txt") catch {};
269269 cwd.deleteFile("new.txt") catch {};
270270
271 try cwd.writeFile("example.txt", "example");
271 try cwd.writeFile(.{ .sub_path = "example.txt", .data = "example" });
272272 try posix.link("example.txt", "new.txt", 0);
273273
274274 const efd = try cwd.openFile("example.txt", .{});
......@@ -312,7 +312,7 @@ test "linkat with different directories" {
312312 cwd.deleteFile("example.txt") catch {};
313313 tmp.dir.deleteFile("new.txt") catch {};
314314
315 try cwd.writeFile("example.txt", "example");
315 try cwd.writeFile(.{ .sub_path = "example.txt", .data = "example" });
316316 try posix.linkat(cwd.fd, "example.txt", tmp.dir.fd, "new.txt", 0);
317317
318318 const efd = try cwd.openFile("example.txt", .{});
......@@ -348,7 +348,7 @@ test "fstatat" {
348348
349349 // create dummy file
350350 const contents = "nonsense";
351 try tmp.dir.writeFile("file.txt", contents);
351 try tmp.dir.writeFile(.{ .sub_path = "file.txt", .data = contents });
352352
353353 // fetch file's info on the opened fd directly
354354 const file = try tmp.dir.openFile("file.txt", .{});
......@@ -366,7 +366,7 @@ test "readlinkat" {
366366 defer tmp.cleanup();
367367
368368 // create file
369 try tmp.dir.writeFile("file.txt", "nonsense");
369 try tmp.dir.writeFile(.{ .sub_path = "file.txt", .data = "nonsense" });
370370
371371 // create a symbolic link
372372 if (native_os == .windows) {
src/Compilation.zig+2-2
......@@ -4175,7 +4175,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8, owner_mod: *Package.Module
41754175 });
41764176 const out_dep_path = try std.fmt.allocPrint(arena, "{s}.d", .{out_h_path});
41774177
4178 try zig_cache_tmp_dir.writeFile(cimport_basename, c_src);
4178 try zig_cache_tmp_dir.writeFile(.{ .sub_path = cimport_basename, .data = c_src });
41794179 if (comp.verbose_cimport) {
41804180 log.info("C import source: {s}", .{out_h_path});
41814181 }
......@@ -4840,7 +4840,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
48404840 // 1 is CREATEPROCESS_MANIFEST_RESOURCE_ID which is the default ID used for RT_MANIFEST resources
48414841 // 24 is RT_MANIFEST
48424842 const input = try std.fmt.allocPrint(arena, "1 24 \"{s}\"", .{fmtRcEscape(src_path)});
4843 try o_dir.writeFile(rc_basename, input);
4843 try o_dir.writeFile(.{ .sub_path = rc_basename, .data = input });
48444844
48454845 var argv = std.ArrayList([]const u8).init(comp.gpa);
48464846 defer argv.deinit();
src/glibc.zig+2-2
......@@ -755,7 +755,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo
755755 try map_contents.writer().print("GLIBC_{d}.{d}.{d} {{ }};\n", .{ ver.major, ver.minor, ver.patch });
756756 }
757757 }
758 try o_directory.handle.writeFile(all_map_basename, map_contents.items);
758 try o_directory.handle.writeFile(.{ .sub_path = all_map_basename, .data = map_contents.items });
759759 map_contents.deinit(); // The most recent allocation of an arena can be freed :)
760760 }
761761
......@@ -1040,7 +1040,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo
10401040
10411041 var lib_name_buf: [32]u8 = undefined; // Larger than each of the names "c", "pthread", etc.
10421042 const asm_file_basename = std.fmt.bufPrint(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;
1043 try o_directory.handle.writeFile(asm_file_basename, stubs_asm.items);
1043 try o_directory.handle.writeFile(.{ .sub_path = asm_file_basename, .data = stubs_asm.items });
10441044
10451045 try buildSharedLib(comp, arena, comp.global_cache_directory, o_directory, asm_file_basename, lib, prog_node);
10461046 }
src/main.zig+3-3
......@@ -6966,7 +6966,7 @@ fn cmdFetch(
69666966 defer rendered.deinit();
69676967 try ast.renderToArrayList(&rendered, fixups);
69686968
6969 build_root.directory.handle.writeFile(Package.Manifest.basename, rendered.items) catch |err| {
6969 build_root.directory.handle.writeFile(.{ .sub_path = Package.Manifest.basename, .data = rendered.items }) catch |err| {
69706970 fatal("unable to write {s} file: {s}", .{ Package.Manifest.basename, @errorName(err) });
69716971 };
69726972
......@@ -7013,7 +7013,7 @@ fn createDependenciesModule(
70137013 {
70147014 var tmp_dir = try local_cache_directory.handle.makeOpenPath(tmp_dir_sub_path, .{});
70157015 defer tmp_dir.close();
7016 try tmp_dir.writeFile(basename, source);
7016 try tmp_dir.writeFile(.{ .sub_path = basename, .data = source });
70177017 }
70187018
70197019 var hh: Cache.HashHelper = .{};
......@@ -7225,7 +7225,7 @@ const Templates = struct {
72257225 }
72267226 }
72277227
7228 return out_dir.writeFile2(.{
7228 return out_dir.writeFile(.{
72297229 .sub_path = template_path,
72307230 .data = templates.buffer.items,
72317231 .flags = .{ .exclusive = true },
test/src/Cases.zig+1-1
......@@ -1641,7 +1641,7 @@ fn runOneCase(
16411641 var sync_node = update_node.start("write", 0);
16421642 sync_node.activate();
16431643 for (update.files.items) |file| {
1644 try tmp.dir.writeFile(file.path, file.src);
1644 try tmp.dir.writeFile(.{ .sub_path = file.path, .data = file.src });
16451645 }
16461646 sync_node.end();
16471647
test/standalone/windows_bat_args/fuzz.zig+3-3
......@@ -51,15 +51,15 @@ pub fn main() anyerror!void {
5151 const preamble_len = buf.items.len;
5252
5353 try buf.appendSlice(" %*");
54 try tmp.dir.writeFile("args1.bat", buf.items);
54 try tmp.dir.writeFile(.{ .sub_path = "args1.bat", .data = buf.items });
5555 buf.shrinkRetainingCapacity(preamble_len);
5656
5757 try buf.appendSlice(" %1 %2 %3 %4 %5 %6 %7 %8 %9");
58 try tmp.dir.writeFile("args2.bat", buf.items);
58 try tmp.dir.writeFile(.{ .sub_path = "args2.bat", .data = buf.items });
5959 buf.shrinkRetainingCapacity(preamble_len);
6060
6161 try buf.appendSlice(" \"%~1\" \"%~2\" \"%~3\" \"%~4\" \"%~5\" \"%~6\" \"%~7\" \"%~8\" \"%~9\"");
62 try tmp.dir.writeFile("args3.bat", buf.items);
62 try tmp.dir.writeFile(.{ .sub_path = "args3.bat", .data = buf.items });
6363 buf.shrinkRetainingCapacity(preamble_len);
6464
6565 var i: u64 = 0;
test/standalone/windows_bat_args/test.zig+3-3
......@@ -25,15 +25,15 @@ pub fn main() anyerror!void {
2525 const preamble_len = buf.items.len;
2626
2727 try buf.appendSlice(" %*");
28 try tmp.dir.writeFile("args1.bat", buf.items);
28 try tmp.dir.writeFile(.{ .sub_path = "args1.bat", .data = buf.items });
2929 buf.shrinkRetainingCapacity(preamble_len);
3030
3131 try buf.appendSlice(" %1 %2 %3 %4 %5 %6 %7 %8 %9");
32 try tmp.dir.writeFile("args2.bat", buf.items);
32 try tmp.dir.writeFile(.{ .sub_path = "args2.bat", .data = buf.items });
3333 buf.shrinkRetainingCapacity(preamble_len);
3434
3535 try buf.appendSlice(" \"%~1\" \"%~2\" \"%~3\" \"%~4\" \"%~5\" \"%~6\" \"%~7\" \"%~8\" \"%~9\"");
36 try tmp.dir.writeFile("args3.bat", buf.items);
36 try tmp.dir.writeFile(.{ .sub_path = "args3.bat", .data = buf.items });
3737 buf.shrinkRetainingCapacity(preamble_len);
3838
3939 // 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+3-3
......@@ -53,9 +53,9 @@ pub fn main() anyerror!void {
5353 try testExec(allocator, "heLLo", "hello from exe\n");
5454
5555 // now add a .bat
56 try tmp.dir.writeFile("hello.bat", "@echo hello from bat");
56 try tmp.dir.writeFile(.{ .sub_path = "hello.bat", .data = "@echo hello from bat" });
5757 // and a .cmd
58 try tmp.dir.writeFile("hello.cmd", "@echo hello from cmd");
58 try tmp.dir.writeFile(.{ .sub_path = "hello.cmd", .data = "@echo hello from cmd" });
5959
6060 // with extension should find the .bat (case insensitive)
6161 try testExec(allocator, "heLLo.bat", "hello from bat\r\n");
......@@ -87,7 +87,7 @@ pub fn main() anyerror!void {
8787 try testExec(allocator, "heLLo", "hello from bat\r\n");
8888
8989 // Add a hello.exe that is not a valid executable
90 try tmp.dir.writeFile("hello.exe", "invalid");
90 try tmp.dir.writeFile(.{ .sub_path = "hello.exe", .data = "invalid" });
9191
9292 // Trying to execute it with extension will give InvalidExe. This is a special
9393 // case for .EXE extensions, where if they ever try to get executed but they are
test/tests.zig+3-3
......@@ -823,12 +823,12 @@ pub fn addCliTests(b: *std.Build) *Step {
823823
824824 var dir = std.fs.cwd().openDir(tmp_path, .{}) catch @panic("unhandled");
825825 defer dir.close();
826 dir.writeFile("fmt1.zig", unformatted_code) catch @panic("unhandled");
827 dir.writeFile("fmt2.zig", unformatted_code) catch @panic("unhandled");
826 dir.writeFile(.{ .sub_path = "fmt1.zig", .data = unformatted_code }) catch @panic("unhandled");
827 dir.writeFile(.{ .sub_path = "fmt2.zig", .data = unformatted_code }) catch @panic("unhandled");
828828 dir.makeDir("subdir") catch @panic("unhandled");
829829 var subdir = dir.openDir("subdir", .{}) catch @panic("unhandled");
830830 defer subdir.close();
831 subdir.writeFile("fmt3.zig", unformatted_code) catch @panic("unhandled");
831 subdir.writeFile(.{ .sub_path = "fmt3.zig", .data = unformatted_code }) catch @panic("unhandled");
832832
833833 // Test zig fmt affecting only the appropriate files.
834834 const run1 = b.addSystemCommand(&.{ b.graph.zig_exe, "fmt", "fmt1.zig" });
tools/process_headers.zig+2-2
......@@ -467,7 +467,7 @@ pub fn main() !void {
467467 // worth it to make it generic
468468 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* });
469469 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
470 try std.fs.cwd().writeFile(full_path, best_contents.bytes);
470 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = best_contents.bytes });
471471 best_contents.is_generic = true;
472472 while (contents_list.popOrNull()) |contender| {
473473 if (contender.hit_count > 1) {
......@@ -497,7 +497,7 @@ pub fn main() !void {
497497 });
498498 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, out_subpath, path_kv.key_ptr.* });
499499 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
500 try std.fs.cwd().writeFile(full_path, contents.bytes);
500 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = contents.bytes });
501501 }
502502 }
503503}
tools/update-linux-headers.zig+2-2
......@@ -275,7 +275,7 @@ pub fn main() !void {
275275 // worth it to make it generic
276276 const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* });
277277 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
278 try std.fs.cwd().writeFile(full_path, best_contents.bytes);
278 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = best_contents.bytes });
279279 best_contents.is_generic = true;
280280 while (contents_list.popOrNull()) |contender| {
281281 if (contender.hit_count > 1) {
......@@ -301,7 +301,7 @@ pub fn main() !void {
301301 const out_subpath = try std.fmt.allocPrint(arena, "{s}-linux-any", .{arch_name});
302302 const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, out_subpath, path_kv.key_ptr.* });
303303 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
304 try std.fs.cwd().writeFile(full_path, contents.bytes);
304 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = contents.bytes });
305305 }
306306 }
307307