Merge pull request #1946 from restic/fix-1945

Remove truncated files from cache
This commit is contained in:
Alexander Neumann 2018-08-12 17:23:56 +02:00
commit 9b513312e2
3 changed files with 15 additions and 1 deletions

View File

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

View File

@ -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()

View File

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