From d81adcfaa546f5378358e2b83267eec4323b3c94 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Thu, 5 Oct 2017 19:30:56 +0200 Subject: [PATCH 1/3] cache: Add file name to error message --- internal/cache/file.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cache/file.go b/internal/cache/file.go index 4239a383c..33836fc03 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 { From d886bc6c48339448dce3a2a7ca5b372897400296 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Thu, 5 Oct 2017 20:39:53 +0200 Subject: [PATCH 2/3] Ignore invalid index files, print warning --- internal/repository/repository.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 { From cebee0b8fa62a31d37bb1a18c5fb9991cfbeaab5 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Thu, 5 Oct 2017 20:40:02 +0200 Subject: [PATCH 3/3] cache: Refuse to cache truncated files --- internal/cache/file.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/cache/file.go b/internal/cache/file.go index 33836fc03..5041ad965 100644 --- a/internal/cache/file.go +++ b/internal/cache/file.go @@ -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") }