| 309 | } |
| 310 | |
| 311 | func newBinMetadataCache(binFS http.FileSystem, binSha1Hashes map[string]string) *binMetadataCache { |
| 312 | b := &binMetadataCache{ |
| 313 | binFS: binFS, |
| 314 | originalHashes: make(map[string]string, len(binSha1Hashes)), |
| 315 | |
| 316 | metadata: make(map[string]binMetadata, len(binSha1Hashes)), |
| 317 | mut: sync.RWMutex{}, |
| 318 | sf: singleflight.Group{}, |
| 319 | sem: make(chan struct{}, 4), |
| 320 | } |
| 321 | |
| 322 | // Previously we copied binSha1Hashes to the cache immediately. Since we now |
| 323 | // read other information like size from the file, we can't do that. Instead |
| 324 | // we copy the hashes to a different map that will be used to populate the |
| 325 | // cache on the first request. |
| 326 | for k, v := range binSha1Hashes { |
| 327 | b.originalHashes[k] = v |
| 328 | } |
| 329 | |
| 330 | return b |
| 331 | } |
| 332 | |
| 333 | func (b *binMetadataCache) getMetadata(name string) (binMetadata, error) { |
| 334 | b.mut.RLock() |