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