mirror of
https://github.com/octoleo/restic.git
synced 2025-01-03 15:17:28 +00:00
cache: Refuse to cache truncated files
This commit is contained in:
parent
d886bc6c48
commit
cebee0b8fa
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 New Issue
Block a user