| ... | ... | @@ -26,6 +26,7 @@ pub fn obtain(cache: *const Cache) Manifest { |
| 26 | 26 | /// This is 128 bits - Even with 2^54 cache entries, the probably of a collision would be under 10^-6 |
| 27 | 27 | pub const bin_digest_len = 16; |
| 28 | 28 | pub const hex_digest_len = bin_digest_len * 2; |
| 29 | pub const BinDigest = [bin_digest_len]u8; |
| 29 | 30 | |
| 30 | 31 | const manifest_file_size_max = 50 * 1024 * 1024; |
| 31 | 32 | |
| ... | ... | @@ -41,7 +42,7 @@ pub const File = struct { |
| 41 | 42 | path: ?[]const u8, |
| 42 | 43 | max_file_size: ?usize, |
| 43 | 44 | stat: fs.File.Stat, |
| 44 | | bin_digest: [bin_digest_len]u8, |
| 45 | bin_digest: BinDigest, |
| 45 | 46 | contents: ?[]const u8, |
| 46 | 47 | |
| 47 | 48 | pub fn deinit(self: *File, allocator: *Allocator) void { |
| ... | ... | @@ -139,16 +140,16 @@ pub const HashHelper = struct { |
| 139 | 140 | return copy.final(); |
| 140 | 141 | } |
| 141 | 142 | |
| 142 | | pub fn peekBin(hh: HashHelper) [bin_digest_len]u8 { |
| 143 | pub fn peekBin(hh: HashHelper) BinDigest { |
| 143 | 144 | var copy = hh; |
| 144 | | var bin_digest: [bin_digest_len]u8 = undefined; |
| 145 | var bin_digest: BinDigest = undefined; |
| 145 | 146 | copy.hasher.final(&bin_digest); |
| 146 | 147 | return bin_digest; |
| 147 | 148 | } |
| 148 | 149 | |
| 149 | 150 | /// Returns a hex encoded hash of the inputs, mutating the state of the hasher. |
| 150 | 151 | pub fn final(hh: *HashHelper) [hex_digest_len]u8 { |
| 151 | | var bin_digest: [bin_digest_len]u8 = undefined; |
| 152 | var bin_digest: BinDigest = undefined; |
| 152 | 153 | hh.hasher.final(&bin_digest); |
| 153 | 154 | |
| 154 | 155 | var out_digest: [hex_digest_len]u8 = undefined; |
| ... | ... | @@ -241,7 +242,7 @@ pub const Manifest = struct { |
| 241 | 242 | const ext = ".txt"; |
| 242 | 243 | var manifest_file_path: [self.hex_digest.len + ext.len]u8 = undefined; |
| 243 | 244 | |
| 244 | | var bin_digest: [bin_digest_len]u8 = undefined; |
| 245 | var bin_digest: BinDigest = undefined; |
| 245 | 246 | self.hash.hasher.final(&bin_digest); |
| 246 | 247 | |
| 247 | 248 | _ = std.fmt.bufPrint(&self.hex_digest, "{x}", .{bin_digest}) catch unreachable; |
| ... | ... | @@ -347,7 +348,7 @@ pub const Manifest = struct { |
| 347 | 348 | cache_hash_file.stat.inode = 0; |
| 348 | 349 | } |
| 349 | 350 | |
| 350 | | var actual_digest: [bin_digest_len]u8 = undefined; |
| 351 | var actual_digest: BinDigest = undefined; |
| 351 | 352 | try hashFile(this_file, &actual_digest); |
| 352 | 353 | |
| 353 | 354 | if (!mem.eql(u8, &cache_hash_file.bin_digest, &actual_digest)) { |
| ... | ... | @@ -381,7 +382,7 @@ pub const Manifest = struct { |
| 381 | 382 | return true; |
| 382 | 383 | } |
| 383 | 384 | |
| 384 | | pub fn unhit(self: *Manifest, bin_digest: [bin_digest_len]u8, input_file_count: usize) void { |
| 385 | pub fn unhit(self: *Manifest, bin_digest: BinDigest, input_file_count: usize) void { |
| 385 | 386 | // Reset the hash. |
| 386 | 387 | self.hash.hasher = hasher_init; |
| 387 | 388 | self.hash.hasher.update(&bin_digest); |
| ... | ... | @@ -530,7 +531,7 @@ pub const Manifest = struct { |
| 530 | 531 | // cache_release is called we still might be working on creating |
| 531 | 532 | // the artifacts to cache. |
| 532 | 533 | |
| 533 | | var bin_digest: [bin_digest_len]u8 = undefined; |
| 534 | var bin_digest: BinDigest = undefined; |
| 534 | 535 | self.hash.hasher.final(&bin_digest); |
| 535 | 536 | |
| 536 | 537 | var out_digest: [hex_digest_len]u8 = undefined; |