| ... | @@ -1706,18 +1706,29 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 { | ... | @@ -1706,18 +1706,29 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 { |
| 1706 | // The args file is already present from a previous run. | 1706 | // The args file is already present from a previous run. |
| 1707 | } else |err| switch (err) { | 1707 | } else |err| switch (err) { |
| 1708 | error.FileNotFound => { | 1708 | error.FileNotFound => { |
| 1709 | try b.cache_root.handle.createDirPath(io, "tmp"); | 1709 | var af = b.cache_root.handle.createFileAtomic(io, args_file, .{ |
| 1710 | const rand_int = std.crypto.random.int(u64); | 1710 | .replace = false, |
| 1711 | const tmp_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(rand_int); | 1711 | .make_path = true, |
| 1712 | try b.cache_root.handle.writeFile(io, .{ .sub_path = tmp_path, .data = args }); | 1712 | }) catch |e| return step.fail("failed creating tmp args file {f}{s}: {t}", .{ |
| 1713 | defer b.cache_root.handle.deleteFile(io, tmp_path) catch { | 1713 | b.cache_root, args_file, e, |
| 1714 | // It's fine if the temporary file can't be cleaned up. | 1714 | }); |
| | 1715 | defer af.deinit(io); |
| | 1716 | |
| | 1717 | af.file.writeStreamingAll(io, args) catch |e| { |
| | 1718 | return step.fail("failed writing args data to tmp file {f}{s}: {t}", .{ |
| | 1719 | b.cache_root, args_file, e, |
| | 1720 | }); |
| 1715 | }; | 1721 | }; |
| 1716 | b.cache_root.handle.rename(tmp_path, b.cache_root.handle, args_file, io) catch |rename_err| switch (rename_err) { | 1722 | // Note we can't clean up this file, not even after build |
| | 1723 | // success, because that might interfere with another build |
| | 1724 | // process that needs the same file. |
| | 1725 | af.link(io) catch |e| switch (e) { |
| 1717 | error.PathAlreadyExists => { | 1726 | error.PathAlreadyExists => { |
| 1718 | // The args file was created by another concurrent build process. | 1727 | // The args file was created by another concurrent build process. |
| 1719 | }, | 1728 | }, |
| 1720 | else => |other_err| return other_err, | 1729 | else => |other_err| return step.fail("failed linking tmp file {f}{s}: {t}", .{ |
| | 1730 | b.cache_root, args_file, other_err, |
| | 1731 | }), |
| 1721 | }; | 1732 | }; |
| 1722 | }, | 1733 | }, |
| 1723 | else => |other_err| return other_err, | 1734 | else => |other_err| return other_err, |