From 5dd0df0162b2dca58f4b3c650bbb46ae06a3adf8 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 11 Aug 2018 22:47:01 +0200 Subject: [PATCH 1/3] cache: Remove files from cache which are too small --- internal/cache/file.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/cache/file.go b/internal/cache/file.go index f232bc7c1..32ad237bf 100644 --- a/internal/cache/file.go +++ b/internal/cache/file.go @@ -63,6 +63,12 @@ func (c *Cache) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, return nil, errors.Errorf("cached file %v is truncated, removing", h) } + if fi.Size() < offset+int64(length) { + _ = f.Close() + _ = c.Remove(h) + return nil, errors.Errorf("cached file %v is too small, removing", h) + } + if offset > 0 { if _, err = f.Seek(offset, io.SeekStart); err != nil { _ = f.Close() From 04f7c054cdaaa51f8b74d6f9bb94cf54b8881076 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 11 Aug 2018 22:54:22 +0200 Subject: [PATCH 2/3] Add entry to changelog --- changelog/unreleased/issue-1935 | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/issue-1935 diff --git a/changelog/unreleased/issue-1935 b/changelog/unreleased/issue-1935 new file mode 100644 index 000000000..4edc64a92 --- /dev/null +++ b/changelog/unreleased/issue-1935 @@ -0,0 +1,8 @@ +Bugfix: Remove truncated files from cache + +When a file in the local cache is truncated, and restic tries to access data +beyond the end of the (cached) file, it used to return an error "EOF". This is +now fixed, such truncated files are removed and the data is fetched directly +from the backend. + +https://github.com/restic/restic/issues/1935 From 0f83fea00711f3ede6cdb526ebd6d92508f56034 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 11 Aug 2018 23:11:51 +0200 Subject: [PATCH 3/3] cache: Fix test for new behavior Accessing beyond the end of the file now removes the file from the cache because it is assumed to be truncated. Usually, this means that the data is fetched directly from the backend instead. --- internal/cache/file_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cache/file_test.go b/internal/cache/file_test.go index 35ce762c0..cf275c84e 100644 --- a/internal/cache/file_test.go +++ b/internal/cache/file_test.go @@ -218,7 +218,7 @@ func TestFileLoad(t *testing.T) { {32*1024 + 5, 0}, {0, 123}, {0, 64*1024 + 234}, - {100, 5234142}, + {100, 5234142 - 100}, } for _, test := range tests {