mirror of
https://github.com/restic/restic.git
synced 2025-12-25 01:41:33 +00:00
repository: make reloading broken files explicit
This commit is contained in:
11
internal/cache/backend.go
vendored
11
internal/cache/backend.go
vendored
@@ -161,14 +161,10 @@ func (b *Backend) Load(ctx context.Context, h backend.Handle, length int, offset
|
||||
// try loading from cache without checking that the handle is actually cached
|
||||
inCache, err := b.loadFromCache(h, length, offset, consumer)
|
||||
if inCache {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// drop from cache and retry once
|
||||
_ = b.Cache.remove(h)
|
||||
debug.Log("error loading %v from cache: %v", h, err)
|
||||
// the caller must explicitly use cache.Forget() to remove the cache entry
|
||||
return err
|
||||
}
|
||||
debug.Log("error loading %v from cache: %v", h, err)
|
||||
|
||||
// if we don't automatically cache this file type, fall back to the backend
|
||||
if !autoCacheTypes(h) {
|
||||
@@ -184,6 +180,7 @@ func (b *Backend) Load(ctx context.Context, h backend.Handle, length int, offset
|
||||
|
||||
inCache, err = b.loadFromCache(h, length, offset, consumer)
|
||||
if inCache {
|
||||
debug.Log("error loading %v from cache: %v", h, err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
10
internal/cache/file.go
vendored
10
internal/cache/file.go
vendored
@@ -55,14 +55,12 @@ func (c *Cache) load(h backend.Handle, length int, offset int64) (io.ReadCloser,
|
||||
size := fi.Size()
|
||||
if size <= int64(crypto.CiphertextLength(0)) {
|
||||
_ = f.Close()
|
||||
_ = c.remove(h)
|
||||
return nil, errors.Errorf("cached file %v is truncated, removing", h)
|
||||
return nil, errors.Errorf("cached file %v is truncated", h)
|
||||
}
|
||||
|
||||
if size < offset+int64(length) {
|
||||
_ = f.Close()
|
||||
_ = c.remove(h)
|
||||
return nil, errors.Errorf("cached file %v is too short, removing", h)
|
||||
return nil, errors.Errorf("cached file %v is too short", h)
|
||||
}
|
||||
|
||||
if offset > 0 {
|
||||
@@ -139,6 +137,10 @@ func (c *Cache) save(h backend.Handle, rd io.Reader) error {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
func (c *Cache) Forget(h backend.Handle) error {
|
||||
return c.remove(h)
|
||||
}
|
||||
|
||||
// remove deletes a file. When the file is not cached, no error is returned.
|
||||
func (c *Cache) remove(h backend.Handle) error {
|
||||
if !c.canBeCached(h.Type) {
|
||||
|
||||
Reference in New Issue
Block a user