| ... | ... | @@ -7,7 +7,6 @@ const testing = @import("testing.zig"); |
| 7 | 7 | const mem = @import("mem.zig"); |
| 8 | 8 | const fmt = @import("fmt.zig"); |
| 9 | 9 | const Allocator = mem.Allocator; |
| 10 | | const Buffer = @import("buffer.zig").Buffer; |
| 11 | 10 | const os = @import("os.zig"); |
| 12 | 11 | |
| 13 | 12 | const base64_encoder = fs.base64_encoder; |
| ... | ... | @@ -45,7 +44,7 @@ pub const CacheHash = struct { |
| 45 | 44 | |
| 46 | 45 | pub fn init(alloc: *Allocator, manifest_dir_path: []const u8) !@This() { |
| 47 | 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 }); |
| 49 | 48 | |
| 50 | 49 | return CacheHash{ |
| 51 | 50 | .alloc = alloc, |
| ... | ... | @@ -149,10 +148,10 @@ pub const CacheHash = struct { |
| 149 | 148 | } |
| 150 | 149 | |
| 151 | 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 | 152 | defer self.alloc.free(file_contents); |
| 154 | 153 | |
| 155 | | const input_file_count = self.files.len; |
| 154 | const input_file_count = self.files.items.len; |
| 156 | 155 | var any_file_changed = false; |
| 157 | 156 | var line_iter = mem.tokenize(file_contents, "\n"); |
| 158 | 157 | var idx: usize = 0; |
| ... | ... | @@ -274,16 +273,17 @@ pub const CacheHash = struct { |
| 274 | 273 | debug.assert(self.manifest_file != null); |
| 275 | 274 | |
| 276 | 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 | 278 | defer contents.deinit(); |
| 279 | 279 | |
| 280 | 280 | for (self.files.toSlice()) |file| { |
| 281 | 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 | } |
| 284 | 284 | |
| 285 | 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 | } |
| 288 | 288 | |
| 289 | 289 | pub fn release(self: *@This()) void { |
| ... | ... | @@ -306,9 +306,8 @@ pub const CacheHash = struct { |
| 306 | 306 | |
| 307 | 307 | fn hash_file(alloc: *Allocator, bin_digest: []u8, handle: *const fs.File) !void { |
| 308 | 308 | var blake3 = Blake3.init(); |
| 309 | | var in_stream = handle.inStream().stream; |
| 310 | 309 | |
| 311 | | const contents = try handle.inStream().stream.readAllAlloc(alloc, 64 * 1024); |
| 310 | const contents = try handle.inStream().readAllAlloc(alloc, 64 * 1024); |
| 312 | 311 | defer alloc.free(contents); |
| 313 | 312 | |
| 314 | 313 | blake3.update(contents); |