authorgravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-04-07 20:12:21-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-25 13:48:43-04:00
log7917f25b0a8e8d8cafea3bacbb13a3c2b03b9a97
tree438ca68f558a100d1dfc939be21f38446a8ed47d
parent16c54990989fa8b25038536b04d2ec6cf99e2e1c

Update cache_hash to zig master


1 files changed, 8 insertions(+), 9 deletions(-)

lib/std/cache_hash.zig+8-9
......@@ -7,7 +7,6 @@ const testing = @import("testing.zig");
77const mem = @import("mem.zig");
88const fmt = @import("fmt.zig");
99const Allocator = mem.Allocator;
10const Buffer = @import("buffer.zig").Buffer;
1110const os = @import("os.zig");
1211
1312const base64_encoder = fs.base64_encoder;
......@@ -45,7 +44,7 @@ pub const CacheHash = struct {
4544
4645 pub fn init(alloc: *Allocator, manifest_dir_path: []const u8) !@This() {
4746 try fs.cwd().makePath(manifest_dir_path);
48 const manifest_dir = try fs.cwd().openDirTraverse(manifest_dir_path);
47 const manifest_dir = try fs.cwd().openDir(manifest_dir_path, .{ .iterate = true });
4948
5049 return CacheHash{
5150 .alloc = alloc,
......@@ -149,10 +148,10 @@ pub const CacheHash = struct {
149148 }
150149
151150 // TODO: Figure out a good max value?
152 const file_contents = try self.manifest_file.?.inStream().stream.readAllAlloc(self.alloc, 16 * 1024);
151 const file_contents = try self.manifest_file.?.inStream().readAllAlloc(self.alloc, 16 * 1024);
153152 defer self.alloc.free(file_contents);
154153
155 const input_file_count = self.files.len;
154 const input_file_count = self.files.items.len;
156155 var any_file_changed = false;
157156 var line_iter = mem.tokenize(file_contents, "\n");
158157 var idx: usize = 0;
......@@ -274,16 +273,17 @@ pub const CacheHash = struct {
274273 debug.assert(self.manifest_file != null);
275274
276275 var encoded_digest: [BASE64_DIGEST_LEN]u8 = undefined;
277 var contents = try Buffer.init(self.alloc, "");
276 var contents = ArrayList(u8).init(self.alloc);
277 var outStream = contents.outStream();
278278 defer contents.deinit();
279279
280280 for (self.files.toSlice()) |file| {
281281 base64_encoder.encode(encoded_digest[0..], &file.bin_digest);
282 try contents.print("{} {} {}\n", .{ file.stat.mtime, encoded_digest[0..], file.path });
282 try outStream.print("{} {} {}\n", .{ file.stat.mtime, encoded_digest[0..], file.path });
283283 }
284284
285285 try self.manifest_file.?.seekTo(0);
286 try self.manifest_file.?.writeAll(contents.toSlice());
286 try self.manifest_file.?.writeAll(contents.items);
287287 }
288288
289289 pub fn release(self: *@This()) void {
......@@ -306,9 +306,8 @@ pub const CacheHash = struct {
306306
307307fn hash_file(alloc: *Allocator, bin_digest: []u8, handle: *const fs.File) !void {
308308 var blake3 = Blake3.init();
309 var in_stream = handle.inStream().stream;
310309
311 const contents = try handle.inStream().stream.readAllAlloc(alloc, 64 * 1024);
310 const contents = try handle.inStream().readAllAlloc(alloc, 64 * 1024);
312311 defer alloc.free(contents);
313312
314313 blake3.update(contents);