diff options
Diffstat (limited to 'pack_pack.go')
| -rw-r--r-- | pack_pack.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pack_pack.go b/pack_pack.go index 5c2c8628..d7b565f5 100644 --- a/pack_pack.go +++ b/pack_pack.go @@ -570,3 +570,27 @@ func (pf *packFile) cursor(ofs uint64) (io.Reader, error) { } return bytes.NewReader(pf.data[ofs:]), nil } + +func (repo *Repository) packFile(rel string) (*packFile, error) { + repo.packFilesMu.RLock() + pf, ok := repo.packFiles[rel] + repo.packFilesMu.RUnlock() + if ok { + return pf, nil + } + + pf, err := openPackFile(repo.repoPath(rel), rel) + if err != nil { + return nil, err + } + + repo.packFilesMu.Lock() + if existing, ok := repo.packFiles[rel]; ok { + repo.packFilesMu.Unlock() + _ = pf.Close() + return existing, nil + } + repo.packFiles[rel] = pf + repo.packFilesMu.Unlock() + return pf, nil +} |
