Skip to content

Commit b86c4bd

Browse files
squeek502andrewrk
authored andcommitted
Rename Dir.writeFile2 -> Dir.writeFile and update all callsites
writeFile was deprecated in favor of writeFile2 in f645022. This commit renames writeFile2 to writeFile and makes writeFile2 a compile error.
1 parent a52f12a commit b86c4bd

23 files changed

+83
-82
lines changed

lib/compiler/build_runner.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ pub fn readSmallFile(dir: fs.Dir, sub_path: []const u8, buffer: []u8) ![]u8 {
10051005
pub 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,18 +2339,6 @@ fn deleteTreeOpenInitialSubpath(self: Dir, sub_path: []const u8, kind_hint: File
23392339

23402340
pub 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.
2346-
pub 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-
23542342
pub 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.
2364-
pub fn writeFile2(self: Dir, options: WriteFileOptions) WriteFileError!void {
2352+
pub 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

2358+
pub const writeFile2 = @compileError("deprecated; renamed to writeFile");
2359+
23702360
pub const AccessError = posix.AccessError;
23712361

23722362
/// Test accessing `sub_path`.

lib/std/fs/test.zig

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

0 commit comments

Comments
 (0)