Merge pull request #1946 from restic/fix-1945
Remove truncated files from cache
This commit is contained in:
commit
9b513312e2
3 changed files with 15 additions and 1 deletions
8
changelog/unreleased/issue-1935
Normal file
8
changelog/unreleased/issue-1935
Normal 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
|
6
internal/cache/file.go
vendored
6
internal/cache/file.go
vendored
|
@ -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()
|
||||
|
|
2
internal/cache/file_test.go
vendored
2
internal/cache/file_test.go
vendored
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue