authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-26 21:12:20+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-26 21:12:20+01:00
logebb2f208159c46fed3aadfcefd2a5524bc46011b
tree1ab51cc0e8819b43c867247d8b26ddb63ae8da8d
parenta8f8d8221595a422b61ceca8835c677f6830799d

stage2 macho: Dir.copyFile does the rename for us!


1 files changed, 1 insertions(+), 10 deletions(-)

src/link.zig+1-10
...@@ -254,17 +254,8 @@ pub const File = struct {...@@ -254,17 +254,8 @@ pub const File = struct {
254 // into a new inode, remove the original file, and rename the copy to match254 // into a new inode, remove the original file, and rename the copy to match
255 // the original file. This is super messy, but there doesn't seem any other255 // the original file. This is super messy, but there doesn't seem any other
256 // way to please the XNU.256 // way to please the XNU.
257 const random_bytes_len = 12;
258 comptime const random_sub_path_len = std.base64.Base64Encoder.calcSize(random_bytes_len);
259 const emit = base.options.emit orelse return;257 const emit = base.options.emit orelse return;
260 var random_bytes: [random_bytes_len]u8 = undefined;258 try emit.directory.handle.copyFile(emit.sub_path, emit.directory.handle, emit.sub_path, .{});
261 try std.crypto.randomBytes(&random_bytes);
262 var random_sub_path: [random_sub_path_len]u8 = undefined;
263 fs.base64_encoder.encode(&random_sub_path, &random_bytes);
264 const tmp_file_name = try mem.join(base.allocator, "_", &[_][]const u8{ emit.sub_path, random_sub_path[0..] });
265 defer base.allocator.free(tmp_file_name);
266 try emit.directory.handle.copyFile(emit.sub_path, emit.directory.handle, tmp_file_name, .{});
267 try emit.directory.handle.rename(tmp_file_name, emit.sub_path);
268 }259 }
269 f.close();260 f.close();
270 base.file = null;261 base.file = null;