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

This commit is contained in:
Audrius Butkevicius
2020-08-07 07:49:28 +02:00
committed by Jakob Borg
parent 4faa5882f2
commit 00008994e4
2 changed files with 86 additions and 80 deletions
+1 -1
View File
@@ -1317,10 +1317,10 @@ func (f *sendReceiveFolder) copierRoutine(in <-chan copyBlocksState, pullChan ch
if err != nil { if err != nil {
return false return false
} }
defer fd.Close()
srcOffset := int64(state.file.BlockSize()) * int64(index) srcOffset := int64(state.file.BlockSize()) * int64(index)
_, err = fd.ReadAt(buf, srcOffset) _, err = fd.ReadAt(buf, srcOffset)
fd.Close()
if err != nil { if err != nil {
return false return false
} }
+6
View File
@@ -202,6 +202,8 @@ func TestHandleFileWithTemp(t *testing.T) {
} }
func TestCopierFinder(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: // After diff between required and existing we should:
// Copy: 1, 2, 3, 4, 6, 7, 8 // Copy: 1, 2, 3, 4, 6, 7, 8
// Since there is no existing file, nor a temp file // Since there is no existing file, nor a temp file
@@ -219,6 +221,8 @@ func TestCopierFinder(t *testing.T) {
requiredFile.Name = "file2" requiredFile.Name = "file2"
m, f := setupSendReceiveFolder(existingFile) m, f := setupSendReceiveFolder(existingFile)
f.CopyRangeMethod = method
defer cleanupSRFolder(f, m) defer cleanupSRFolder(f, m)
if _, err := prepareTmpFile(f.Filesystem()); err != nil { 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()) t.Errorf("Block %d mismatch: %s != %s", eq, blks[eq-1].String(), blocks[eq].String())
} }
} }
})
}
} }
func TestWeakHash(t *testing.T) { func TestWeakHash(t *testing.T) {