2
2
mirror of https://github.com/octoleo/restic.git synced 2025-01-02 22:50:19 +00:00

cache: Recheck before downloading

This commit is contained in:
Alexander Neumann 2018-10-04 14:30:07 +02:00
parent b1e1b71bab
commit 19725954ee

View File

@ -106,6 +106,11 @@ func (b *Backend) cacheFile(ctx context.Context, h restic.Handle) error {
return nil 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 { err := b.Backend.Load(ctx, h, 0, 0, func(rd io.Reader) error {
return b.Cache.Save(h, rd) 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) delete(b.inProgress, h)
b.inProgressMutex.Unlock() b.inProgressMutex.Unlock()
return err return nil
} }
// loadFromCacheOrDelegate will try to load the file from the cache, and fall // loadFromCacheOrDelegate will try to load the file from the cache, and fall