forked from TrueCloudLab/restic
cache: Always use cached file if it exists
A file is always cached whole. Thus, any out of bounds access will also fail when directed at the backend. To handle case in which the cached file is broken, then caller must call Cache.Forget(h) for the file in question.
This commit is contained in:
parent
8cce06d915
commit
97a307df1a
3 changed files with 29 additions and 24 deletions
7
internal/cache/backend.go
vendored
7
internal/cache/backend.go
vendored
|
@ -40,7 +40,8 @@ func (b *Backend) Remove(ctx context.Context, h backend.Handle) error {
|
|||
return err
|
||||
}
|
||||
|
||||
return b.Cache.remove(h)
|
||||
err = b.Cache.remove(h)
|
||||
return err
|
||||
}
|
||||
|
||||
func autoCacheTypes(h backend.Handle) bool {
|
||||
|
@ -133,9 +134,9 @@ func (b *Backend) cacheFile(ctx context.Context, h backend.Handle) error {
|
|||
|
||||
// loadFromCache will try to load the file from the cache.
|
||||
func (b *Backend) loadFromCache(h backend.Handle, length int, offset int64, consumer func(rd io.Reader) error) (bool, error) {
|
||||
rd, err := b.Cache.load(h, length, offset)
|
||||
rd, inCache, err := b.Cache.load(h, length, offset)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return inCache, err
|
||||
}
|
||||
|
||||
err = consumer(rd)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue