1
0
mirror of https://github.com/restic/restic.git synced 2024-06-29 08:10:52 +02:00

Merge pull request #1333 from restic/fix-1328

Do not cache invalid/truncated files
This commit is contained in:
Alexander Neumann 2017-10-05 21:36:52 +02:00
commit a5c003acb0
2 changed files with 12 additions and 3 deletions

View File

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

View File

@ -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 {