authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-28 22:40:50-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-28 22:40:50-07:00
log73167e80f8a1d440ebc5725a165b7cf484b96170
treecb9eca574d1bc37ccdd2e54732a350f23a75b18a
parentef9582a1ec452aab816b67cd2d0d35ef7356ddae

stage2: fix Cache not calling ftruncate in writeManifest

this led to a corrupt cache when the number of files got smaller. it is now fixed.

2 files changed, 6 insertions(+), 5 deletions(-)

BRANCH_TODO-1
......@@ -1,4 +1,3 @@
1 * docs are failing to build
21 * MachO LLD linking
32 * WASM LLD linking
43 * audit the CLI options for stage2
src/Cache.zig+6-4
......@@ -528,14 +528,15 @@ pub const Manifest = struct {
528528 }
529529
530530 pub fn writeManifest(self: *Manifest) !void {
531 assert(self.manifest_file != null);
531 const manifest_file = self.manifest_file.?;
532532 if (!self.manifest_dirty) return;
533533
534 var encoded_digest: [hex_digest_len]u8 = undefined;
535534 var contents = std.ArrayList(u8).init(self.cache.gpa);
536 var writer = contents.writer();
537535 defer contents.deinit();
538536
537 const writer = contents.writer();
538 var encoded_digest: [hex_digest_len]u8 = undefined;
539
539540 for (self.files.items) |file| {
540541 _ = std.fmt.bufPrint(&encoded_digest, "{x}", .{file.bin_digest}) catch unreachable;
541542 try writer.print("{d} {d} {d} {s} {s}\n", .{
......@@ -547,7 +548,8 @@ pub const Manifest = struct {
547548 });
548549 }
549550
550 try self.manifest_file.?.pwriteAll(contents.items, 0);
551 try manifest_file.setEndPos(contents.items.len);
552 try manifest_file.pwriteAll(contents.items, 0);
551553 self.manifest_dirty = false;
552554 }
553555