Merge pull request #1333 from restic/fix-1328
Do not cache invalid/truncated files
This commit is contained in:
commit
a5c003acb0
2 changed files with 12 additions and 3 deletions
12
internal/cache/file.go
vendored
12
internal/cache/file.go
vendored
|
@ -60,7 +60,7 @@ func (c *Cache) Load(h restic.Handle, length int, offset int64) (io.ReadCloser,
|
|||
if fi.Size() <= crypto.Extension {
|
||||
_ = f.Close()
|
||||
_ = c.Remove(h)
|
||||
return nil, errors.New("cached file is truncated, removing")
|
||||
return nil, errors.Errorf("cached file %v is truncated, removing", h)
|
||||
}
|
||||
|
||||
if offset > 0 {
|
||||
|
@ -111,13 +111,21 @@ func (c *Cache) Save(h restic.Handle, rd io.Reader) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err = io.Copy(f, rd); err != nil {
|
||||
n, err := io.Copy(f, rd)
|
||||
if err != nil {
|
||||
_ = f.Close()
|
||||
_ = c.Remove(h)
|
||||
return errors.Wrap(err, "Copy")
|
||||
}
|
||||
|
||||
if n <= crypto.Extension {
|
||||
_ = f.Close()
|
||||
_ = c.Remove(h)
|
||||
return errors.Errorf("trying to cache truncated file %v", h)
|
||||
}
|
||||
|
||||
if err = f.Close(); err != nil {
|
||||
_ = c.Remove(h)
|
||||
return errors.Wrap(err, "Close")
|
||||
}
|
||||
|
||||
|
|
|
@ -378,7 +378,8 @@ func (r *Repository) LoadIndex(ctx context.Context) error {
|
|||
worker := func(ctx context.Context, id restic.ID) error {
|
||||
idx, err := LoadIndex(ctx, r, id)
|
||||
if err != nil {
|
||||
return err
|
||||
fmt.Fprintf(os.Stderr, "%v, ignoring\n", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
select {
|
||||
|
|
Loading…
Reference in a new issue