Fix cache errors from files with same length/murmur2 fingerprint

This commit is contained in:
comp500 2023-06-23 19:00:35 +01:00
parent d018d7e780
commit dd5520e471

View File

@ -404,8 +404,12 @@ func (c *CacheIndex) rehashFile(cacheHash string, hashFormat string) (string, er
} }
func (c *CacheIndex) NewHandleFromHashes(hashes map[string]string) (*CacheIndexHandle, bool) { func (c *CacheIndex) NewHandleFromHashes(hashes map[string]string) (*CacheIndexHandle, bool) {
for hashFormat, hash := range hashes { // Ensure hashes contains the cache hash format
handle := c.GetHandleFromHash(hashFormat, hash) if _, ok := hashes[cacheHashFormat]; !ok {
panic("NewHandleFromHashes didn't get any value for " + cacheHashFormat)
}
// Only compare with the cache hash format - other hashes might be insecure or likely to collide
handle := c.GetHandleFromHash(cacheHashFormat, hashes[cacheHashFormat])
if handle != nil { if handle != nil {
// Add hashes to handle // Add hashes to handle
for hashFormat2, hash2 := range hashes { for hashFormat2, hash2 := range hashes {
@ -413,7 +417,6 @@ func (c *CacheIndex) NewHandleFromHashes(hashes map[string]string) (*CacheIndexH
} }
return handle, true return handle, true
} }
}
i := c.nextHashIdx i := c.nextHashIdx
c.nextHashIdx += 1 c.nextHashIdx += 1
return &CacheIndexHandle{ return &CacheIndexHandle{