commit 73167e80f8a1d440ebc5725a165b7cf484b96170 (tree)
parent ef9582a1ec452aab816b67cd2d0d35ef7356ddae
Author: Andrew Kelley <andrew@ziglang.org>
Date: Mon, 28 Sep 2020 22:40:50 -0700
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.
Diffstat:
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/BRANCH_TODO b/BRANCH_TODO
@@ -1,4 +1,3 @@
- * docs are failing to build
* MachO LLD linking
* WASM LLD linking
* audit the CLI options for stage2
diff --git a/src/Cache.zig b/src/Cache.zig
@@ -528,14 +528,15 @@ pub const Manifest = struct {
}
pub fn writeManifest(self: *Manifest) !void {
- assert(self.manifest_file != null);
+ const manifest_file = self.manifest_file.?;
if (!self.manifest_dirty) return;
- var encoded_digest: [hex_digest_len]u8 = undefined;
var contents = std.ArrayList(u8).init(self.cache.gpa);
- var writer = contents.writer();
defer contents.deinit();
+ const writer = contents.writer();
+ var encoded_digest: [hex_digest_len]u8 = undefined;
+
for (self.files.items) |file| {
_ = std.fmt.bufPrint(&encoded_digest, "{x}", .{file.bin_digest}) catch unreachable;
try writer.print("{d} {d} {d} {s} {s}\n", .{
@@ -547,7 +548,8 @@ pub const Manifest = struct {
});
}
- try self.manifest_file.?.pwriteAll(contents.items, 0);
+ try manifest_file.setEndPos(contents.items.len);
+ try manifest_file.pwriteAll(contents.items, 0);
self.manifest_dirty = false;
}