lib/model: Don't close file early (fixes #6875) (#6876)

This commit is contained in:
Audrius Butkevicius 2020-08-03 20:54:42 +01:00 committed by Jakob Borg
parent 4faa5882f2
commit 00008994e4
2 changed files with 86 additions and 80 deletions

View File

@ -1317,10 +1317,10 @@ func (f *sendReceiveFolder) copierRoutine(in <-chan copyBlocksState, pullChan ch
if err != nil {
return false
}
defer fd.Close()
srcOffset := int64(state.file.BlockSize()) * int64(index)
_, err = fd.ReadAt(buf, srcOffset)
fd.Close()
if err != nil {
return false
}

View File

@ -202,6 +202,8 @@ func TestHandleFileWithTemp(t *testing.T) {
}
func TestCopierFinder(t *testing.T) {
for _, method := range []fs.CopyRangeMethod{fs.CopyRangeMethodStandard, fs.CopyRangeMethodAllWithFallback} {
t.Run(method.String(), func(t *testing.T) {
// After diff between required and existing we should:
// Copy: 1, 2, 3, 4, 6, 7, 8
// Since there is no existing file, nor a temp file
@ -219,6 +221,8 @@ func TestCopierFinder(t *testing.T) {
requiredFile.Name = "file2"
m, f := setupSendReceiveFolder(existingFile)
f.CopyRangeMethod = method
defer cleanupSRFolder(f, m)
if _, err := prepareTmpFile(f.Filesystem()); err != nil {
@ -291,6 +295,8 @@ func TestCopierFinder(t *testing.T) {
t.Errorf("Block %d mismatch: %s != %s", eq, blks[eq-1].String(), blocks[eq].String())
}
}
})
}
}
func TestWeakHash(t *testing.T) {