| ... | @@ -499,9 +499,10 @@ pub const Manifest = struct { | ... | @@ -499,9 +499,10 @@ pub const Manifest = struct { |
| 499 | pub fn flagsAndPath(off: File.Offset, contents: []const u8) [:0]const u8 { | 499 | pub fn flagsAndPath(off: File.Offset, contents: []const u8) [:0]const u8 { |
| 500 | const flags_off = @offsetOf(File, "flags"); | 500 | const flags_off = @offsetOf(File, "flags"); |
| 501 | comptime assert(@offsetOf(File, "path_start") - flags_off == 1); | 501 | comptime assert(@offsetOf(File, "path_start") - flags_off == 1); |
| 502 | const hash_start = @backingInt(off) + flags_off; | 502 | const start = @backingInt(off) + flags_off; |
| 503 | const hash_end = mem.findScalarPos(u8, contents, hash_start, 0).?; | 503 | // Scan for the sentinel starting from the path_start offset because flags might be zero. |
| 504 | return contents[hash_start..hash_end :0]; | 504 | const end = mem.findScalarPos(u8, contents, start + 1, 0).?; |
| | 505 | return contents[start..end :0]; |
| 505 | } | 506 | } |
| 506 | | 507 | |
| 507 | pub fn pathFallible(off: File.Offset, contents: []const u8) error{InvalidFormat}![:0]const u8 { | 508 | pub fn pathFallible(off: File.Offset, contents: []const u8) error{InvalidFormat}![:0]const u8 { |
| ... | @@ -898,7 +899,8 @@ pub const Manifest = struct { | ... | @@ -898,7 +899,8 @@ pub const Manifest = struct { |
| 898 | // This is *not* hashing the contents of the input files. It is the | 899 | // This is *not* hashing the contents of the input files. It is the |
| 899 | // flags (including prefix) and path only. | 900 | // flags (including prefix) and path only. |
| 900 | for (man.files.keys()[0..man.input_paths.items.len]) |file_off| { | 901 | for (man.files.keys()[0..man.input_paths.items.len]) |file_off| { |
| 901 | man.hashFlagsAndPath(file_off, &man.hash.hasher); | 902 | const flags_and_path = file_off.flagsAndPath(man.contents.items); |
| | 903 | man.hash.hasher.update(mem.absorbSentinel(flags_and_path)); |
| 902 | } | 904 | } |
| 903 | | 905 | |
| 904 | var input_digest: BinDigest = undefined; | 906 | var input_digest: BinDigest = undefined; |
| ... | @@ -2288,10 +2290,6 @@ pub const Manifest = struct { | ... | @@ -2288,10 +2290,6 @@ pub const Manifest = struct { |
| 2288 | hasher.update(contents.items[contents_start..][0..contents_len]); | 2290 | hasher.update(contents.items[contents_start..][0..contents_len]); |
| 2289 | hasher.final(bin_digest); | 2291 | hasher.final(bin_digest); |
| 2290 | } | 2292 | } |
| 2291 | | | |
| 2292 | fn hashFlagsAndPath(m: *const Manifest, off: File.Offset, hasher: *Hasher) void { | | |
| 2293 | hasher.update(off.flagsAndPath(m.contents.items)); | | |
| 2294 | } | | |
| 2295 | }; | 2293 | }; |
| 2296 | | 2294 | |
| 2297 | /// Create/Write a file, close it, then grab its stat.mtime timestamp. | 2295 | /// Create/Write a file, close it, then grab its stat.mtime timestamp. |