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");...@@ -7,7 +7,6 @@ const testing = @import("testing.zig");
7const mem = @import("mem.zig");7const mem = @import("mem.zig");
8const fmt = @import("fmt.zig");8const fmt = @import("fmt.zig");
9const Allocator = mem.Allocator;9const Allocator = mem.Allocator;
10const Buffer = @import("buffer.zig").Buffer;
11const os = @import("os.zig");10const os = @import("os.zig");
1211
13const base64_encoder = fs.base64_encoder;12const base64_encoder = fs.base64_encoder;
...@@ -45,7 +44,7 @@ pub const CacheHash = struct {...@@ -45,7 +44,7 @@ pub const CacheHash = struct {
4544
46 pub fn init(alloc: *Allocator, manifest_dir_path: []const u8) !@This() {45 pub fn init(alloc: *Allocator, manifest_dir_path: []const u8) !@This() {
47 try fs.cwd().makePath(manifest_dir_path);46 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
50 return CacheHash{49 return CacheHash{
51 .alloc = alloc,50 .alloc = alloc,
...@@ -149,10 +148,10 @@ pub const CacheHash = struct {...@@ -149,10 +148,10 @@ pub const CacheHash = struct {
149 }148 }
150149
151 // TODO: Figure out a good max value?150 // 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);
153 defer self.alloc.free(file_contents);152 defer self.alloc.free(file_contents);
154153
155 const input_file_count = self.files.len;154 const input_file_count = self.files.items.len;
156 var any_file_changed = false;155 var any_file_changed = false;
157 var line_iter = mem.tokenize(file_contents, "\n");156 var line_iter = mem.tokenize(file_contents, "\n");
158 var idx: usize = 0;157 var idx: usize = 0;
...@@ -274,16 +273,17 @@ pub const CacheHash = struct {...@@ -274,16 +273,17 @@ pub const CacheHash = struct {
274 debug.assert(self.manifest_file != null);273 debug.assert(self.manifest_file != null);
275274
276 var encoded_digest: [BASE64_DIGEST_LEN]u8 = undefined;275 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();
278 defer contents.deinit();278 defer contents.deinit();
279279
280 for (self.files.toSlice()) |file| {280 for (self.files.toSlice()) |file| {
281 base64_encoder.encode(encoded_digest[0..], &file.bin_digest);281 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 });
283 }283 }
284284
285 try self.manifest_file.?.seekTo(0);285 try self.manifest_file.?.seekTo(0);
286 try self.manifest_file.?.writeAll(contents.toSlice());286 try self.manifest_file.?.writeAll(contents.items);
287 }287 }
288288
289 pub fn release(self: *@This()) void {289 pub fn release(self: *@This()) void {
...@@ -306,9 +306,8 @@ pub const CacheHash = struct {...@@ -306,9 +306,8 @@ pub const CacheHash = struct {
306306
307fn hash_file(alloc: *Allocator, bin_digest: []u8, handle: *const fs.File) !void {307fn hash_file(alloc: *Allocator, bin_digest: []u8, handle: *const fs.File) !void {
308 var blake3 = Blake3.init();308 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);
312 defer alloc.free(contents);311 defer alloc.free(contents);
313312
314 blake3.update(contents);313 blake3.update(contents);