cache: Auto-remove invalid files
This commit is contained in:
parent
176bfa6529
commit
e262f35d0a
1 changed files with 13 additions and 0 deletions
13
internal/cache/file.go
vendored
13
internal/cache/file.go
vendored
|
@ -6,6 +6,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/restic/restic/internal/crypto"
|
||||||
"github.com/restic/restic/internal/debug"
|
"github.com/restic/restic/internal/debug"
|
||||||
"github.com/restic/restic/internal/fs"
|
"github.com/restic/restic/internal/fs"
|
||||||
"github.com/restic/restic/internal/restic"
|
"github.com/restic/restic/internal/restic"
|
||||||
|
@ -50,6 +51,18 @@ func (c *Cache) Load(h restic.Handle, length int, offset int64) (io.ReadCloser,
|
||||||
return nil, errors.Wrap(err, "Open")
|
return nil, errors.Wrap(err, "Open")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fi, err := f.Stat()
|
||||||
|
if err != nil {
|
||||||
|
_ = f.Close()
|
||||||
|
return nil, errors.Wrap(err, "Stat")
|
||||||
|
}
|
||||||
|
|
||||||
|
if fi.Size() <= crypto.Extension {
|
||||||
|
_ = f.Close()
|
||||||
|
_ = c.Remove(h)
|
||||||
|
return nil, errors.New("cached file is truncated, removing")
|
||||||
|
}
|
||||||
|
|
||||||
if offset > 0 {
|
if offset > 0 {
|
||||||
if _, err = f.Seek(offset, io.SeekStart); err != nil {
|
if _, err = f.Seek(offset, io.SeekStart); err != nil {
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
Loading…
Reference in a new issue