cache: Recheck before downloading

This commit is contained in:
Alexander Neumann 2018-10-04 14:30:07 +02:00
parent b1e1b71bab
commit 19725954ee
1 changed files with 6 additions and 1 deletions

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) {
return nil
}
err := b.Backend.Load(ctx, h, 0, 0, func(rd io.Reader) error {
return b.Cache.Save(h, rd)
})
@ -122,7 +127,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