authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-04 21:47:00-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-05 20:28:58-08:00
log39605bd6bc1ce8be4a775e5530a1d866c2a700d7
tree3b3efc766776e0253b25435506e47f05926070ea
parent4365b0df88a300a48abdfcd5534acdb048b465ba

compiler: update to new createFileAtomic API


4 files changed, 28 insertions(+), 22 deletions(-)

lib/std/Io/Threaded.zig-2
...@@ -7545,7 +7545,6 @@ fn dirOpenDirWasi(...@@ -7545,7 +7545,6 @@ fn dirOpenDirWasi(
7545 .NOMEM => return error.SystemResources,7545 .NOMEM => return error.SystemResources,
7546 .NOTDIR => return error.NotDir,7546 .NOTDIR => return error.NotDir,
7547 .PERM => return error.PermissionDenied,7547 .PERM => return error.PermissionDenied,
7548 .BUSY => return error.DeviceBusy,
7549 .NOTCAPABLE => return error.AccessDenied,7548 .NOTCAPABLE => return error.AccessDenied,
7550 .ILSEQ => return error.BadPathName,7549 .ILSEQ => return error.BadPathName,
7551 else => |err| return posix.unexpectedErrno(err),7550 else => |err| return posix.unexpectedErrno(err),
...@@ -14012,7 +14011,6 @@ fn windowsCreateProcessPathExt(...@@ -14012,7 +14011,6 @@ fn windowsCreateProcessPathExt(
14012 error.NetworkNotFound,14011 error.NetworkNotFound,
14013 error.NameTooLong,14012 error.NameTooLong,
14014 error.BadPathName,14013 error.BadPathName,
14015 error.DeviceBusy,
14016 => return error.FileNotFound,14014 => return error.FileNotFound,
14017 };14015 };
14018 };14016 };
src/Builtin.zig+4-4
...@@ -343,10 +343,10 @@ pub fn updateFileOnDisk(file: *File, comp: *Compilation) !void {...@@ -343,10 +343,10 @@ pub fn updateFileOnDisk(file: *File, comp: *Compilation) !void {
343 }343 }
344344
345 // `make_path` matters because the dir hasn't actually been created yet.345 // `make_path` matters because the dir hasn't actually been created yet.
346 var af = try root_dir.atomicFile(io, sub_path, .{ .make_path = true, .write_buffer = &.{} });346 var af = try root_dir.createFileAtomic(io, sub_path, .{ .make_path = true, .replace = true });
347 defer af.deinit();347 defer af.deinit(io);
348 try af.file_writer.interface.writeAll(file.source.?);348 try af.file.writeStreamingAll(io, file.source.?);
349 af.finish() catch |err| switch (err) {349 af.replace(io) catch |err| switch (err) {
350 error.AccessDenied => switch (builtin.os.tag) {350 error.AccessDenied => switch (builtin.os.tag) {
351 .windows => {351 .windows => {
352 // Very likely happened due to another process or thread352 // Very likely happened due to another process or thread
src/Compilation.zig+20-12
...@@ -3916,11 +3916,14 @@ pub fn saveState(comp: *Compilation) !void {...@@ -3916,11 +3916,14 @@ pub fn saveState(comp: *Compilation) !void {
39163916
3917 // Using an atomic file prevents a crash or power failure from corrupting3917 // Using an atomic file prevents a crash or power failure from corrupting
3918 // the previous incremental compilation state.3918 // the previous incremental compilation state.
3919 var af = try lf.emit.root_dir.handle.createFileAtomic(io, basename, .{ .replace = true });
3920 defer af.deinit(io);
3921
3919 var write_buffer: [1024]u8 = undefined;3922 var write_buffer: [1024]u8 = undefined;
3920 var af = try lf.emit.root_dir.handle.atomicFile(io, basename, .{ .write_buffer = &write_buffer });3923 var file_writer = af.file.writer(io, &write_buffer);
3921 defer af.deinit();3924 try file_writer.interface.writeVecAll(bufs.items);
3922 try af.file_writer.interface.writeVecAll(bufs.items);3925 try file_writer.interface.flush();
3923 try af.finish();3926 try af.replace(io);
3924}3927}
39253928
3926fn addBuf(list: *std.array_list.Managed([]const u8), buf: []const u8) void {3929fn addBuf(list: *std.array_list.Managed([]const u8), buf: []const u8) void {
...@@ -5244,26 +5247,31 @@ fn processOneJob(...@@ -5244,26 +5247,31 @@ fn processOneJob(
5244 }5247 }
5245}5248}
52465249
5247fn createDepFile(comp: *Compilation, depfile: []const u8, binfile: Cache.Path) anyerror!void {5250fn createDepFile(comp: *Compilation, dep_file: []const u8, bin_file: Cache.Path) anyerror!void {
5248 const io = comp.io;5251 const io = comp.io;
5249 var buf: [4096]u8 = undefined;
5250 var af = try Io.Dir.cwd().atomicFile(io, depfile, .{ .write_buffer = &buf });
5251 defer af.deinit();
52525252
5253 comp.writeDepFile(binfile, &af.file_writer.interface) catch return af.file_writer.err.?;5253 var af = try Io.Dir.cwd().createFileAtomic(io, dep_file, .{ .replace = true });
5254 defer af.deinit(io);
52545255
5255 try af.finish();5256 var buf: [4096]u8 = undefined;
5257 var file_writer = af.file.writer(io, &buf);
5258
5259 comp.writeDepFile(bin_file, &file_writer.interface) catch |err| switch (err) {
5260 error.WriteFailed => return file_writer.err.?,
5261 };
5262 try file_writer.flush();
5263 try af.replace(io);
5256}5264}
52575265
5258fn writeDepFile(5266fn writeDepFile(
5259 comp: *Compilation,5267 comp: *Compilation,
5260 binfile: Cache.Path,5268 bin_file: Cache.Path,
5261 w: *std.Io.Writer,5269 w: *std.Io.Writer,
5262) std.Io.Writer.Error!void {5270) std.Io.Writer.Error!void {
5263 const prefixes = comp.cache_parent.prefixes();5271 const prefixes = comp.cache_parent.prefixes();
5264 const fsi = comp.file_system_inputs.?.items;5272 const fsi = comp.file_system_inputs.?.items;
52655273
5266 try w.print("{f}:", .{binfile});5274 try w.print("{f}:", .{bin_file});
52675275
5268 {5276 {
5269 var it = std.mem.splitScalar(u8, fsi, 0);5277 var it = std.mem.splitScalar(u8, fsi, 0);
src/fmt.zig+4-4
...@@ -355,11 +355,11 @@ fn fmtPathFile(...@@ -355,11 +355,11 @@ fn fmtPathFile(
355 try fmt.stdout_writer.interface.print("{s}\n", .{file_path});355 try fmt.stdout_writer.interface.print("{s}\n", .{file_path});
356 fmt.any_error = true;356 fmt.any_error = true;
357 } else {357 } else {
358 var af = try dir.atomicFile(io, sub_path, .{ .permissions = stat.permissions, .write_buffer = &.{} });358 var af = try dir.createFileAtomic(io, sub_path, .{ .permissions = stat.permissions, .replace = true });
359 defer af.deinit();359 defer af.deinit(io);
360360
361 try af.file_writer.interface.writeAll(fmt.out_buffer.written());361 try af.file.writeStreamingAll(io, fmt.out_buffer.written());
362 try af.finish();362 try af.replace(io);
363 try fmt.stdout_writer.interface.print("{s}\n", .{file_path});363 try fmt.stdout_writer.interface.print("{s}\n", .{file_path});
364 }364 }
365}365}