forked from TrueCloudLab/restic
cache: Refuse to cache truncated files
This commit is contained in:
parent
d886bc6c48
commit
cebee0b8fa
1 changed files with 9 additions and 1 deletions
10
internal/cache/file.go
vendored
10
internal/cache/file.go
vendored
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue