mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-05 21:07:58 +00:00
lib/scanner: When scanning a file, stick to the size given by Lstat (fixes #3440)
Otherwise if the file grows during scanning the block list will be out of sync with the stated size and things get confused. We could fixup the size afterwards based on the block list, but then we might see other inconsistencies as the mtime should have changed to reflect the new size etc. Better stick to the original state and let the next scan pick up the change. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3442
This commit is contained in:
parent
0f28626bb4
commit
2a6f164923
@ -31,7 +31,8 @@ func Blocks(r io.Reader, blocksize int, sizehint int64, counter Counter) ([]prot
|
|||||||
|
|
||||||
if sizehint > 0 {
|
if sizehint > 0 {
|
||||||
// Allocate contiguous blocks for the BlockInfo structures and their
|
// Allocate contiguous blocks for the BlockInfo structures and their
|
||||||
// hashes once and for all.
|
// hashes once and for all, and stick to the specified size.
|
||||||
|
r = io.LimitReader(r, sizehint)
|
||||||
numBlocks := int(sizehint / int64(blocksize))
|
numBlocks := int(sizehint / int64(blocksize))
|
||||||
blocks = make([]protocol.BlockInfo, 0, numBlocks)
|
blocks = make([]protocol.BlockInfo, 0, numBlocks)
|
||||||
hashes = make([]byte, 0, hashLength*numBlocks)
|
hashes = make([]byte, 0, hashLength*numBlocks)
|
||||||
|
Loading…
Reference in New Issue
Block a user