2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 23:06:32 +00:00

Merge pull request #2019 from restic/recheck-cache

cache: Recheck before downloading
This commit is contained in:
Alexander Neumann 2018-10-05 12:26:21 +02:00
commit 233596f4bc

View File

@ -106,6 +106,11 @@ func (b *Backend) cacheFile(ctx context.Context, h restic.Handle) error {
return nil
}
// test again, maybe the file was cached in the meantime
if !b.Cache.Has(h) {
// nope, it's still not in the cache, pull it from the repo and save it
err := b.Backend.Load(ctx, h, 0, 0, func(rd io.Reader) error {
return b.Cache.Save(h, rd)
})
@ -113,6 +118,7 @@ func (b *Backend) cacheFile(ctx context.Context, h restic.Handle) error {
// try to remove from the cache, ignore errors
_ = b.Cache.Remove(h)
}
}
// signal other waiting goroutines that the file may now be cached
close(finish)
@ -122,7 +128,7 @@ func (b *Backend) cacheFile(ctx context.Context, h restic.Handle) error {
delete(b.inProgress, h)
b.inProgressMutex.Unlock()
return err
return nil
}
// loadFromCacheOrDelegate will try to load the file from the cache, and fall