cache: Refuse to cache truncated files

This commit is contained in:
Alexander Neumann 2017-10-05 20:40:02 +02:00
parent d886bc6c48
commit cebee0b8fa

View file

@ -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")
}