diff --git a/internal/cache/file.go b/internal/cache/file.go index 4239a383c..5041ad965 100644 --- a/internal/cache/file.go +++ b/internal/cache/file.go @@ -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") } diff --git a/internal/repository/repository.go b/internal/repository/repository.go index 96eb932d9..e2d870780 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -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 {