mirror of
https://github.com/restic/restic.git
synced 2024-12-24 08:44:52 +00:00
Merge pull request #2019 from restic/recheck-cache
cache: Recheck before downloading
This commit is contained in:
commit
233596f4bc
1 changed files with 13 additions and 7 deletions
20
internal/cache/backend.go
vendored
20
internal/cache/backend.go
vendored
|
@ -106,12 +106,18 @@ func (b *Backend) cacheFile(ctx context.Context, h restic.Handle) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := b.Backend.Load(ctx, h, 0, 0, func(rd io.Reader) error {
|
// test again, maybe the file was cached in the meantime
|
||||||
return b.Cache.Save(h, rd)
|
if !b.Cache.Has(h) {
|
||||||
})
|
|
||||||
if err != nil {
|
// nope, it's still not in the cache, pull it from the repo and save it
|
||||||
// try to remove from the cache, ignore errors
|
|
||||||
_ = b.Cache.Remove(h)
|
err := b.Backend.Load(ctx, h, 0, 0, func(rd io.Reader) error {
|
||||||
|
return b.Cache.Save(h, rd)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
// try to remove from the cache, ignore errors
|
||||||
|
_ = b.Cache.Remove(h)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// signal other waiting goroutines that the file may now be cached
|
// signal other waiting goroutines that the file may now be cached
|
||||||
|
@ -122,7 +128,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
|
||||||
|
|
Loading…
Reference in a new issue