Skip to content

Commit

Permalink
cache: Fix recheck logic, remove channel from inProgress
Browse files Browse the repository at this point in the history
  • Loading branch information
fd0 committed Oct 4, 2018
1 parent 1972595 commit 5971650
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions internal/cache/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,17 @@ func (b *Backend) cacheFile(ctx context.Context, h restic.Handle) error {
}

// test again, maybe the file was cached in the meantime
if b.Cache.Has(h) {
return nil
}
if !b.Cache.Has(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)
// 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)
})
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
Expand Down

0 comments on commit 5971650

Please sign in to comment.