From aa168ec2d6516f09f0cf645adcffa3b7093f2820 Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Fri, 17 Oct 2014 23:16:29 +0100 Subject: [PATCH] Populate block offsets even if the blocks are not diffed --- internal/model/puller.go | 2 ++ internal/scanner/blocks.go | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/internal/model/puller.go b/internal/model/puller.go index ffc7bea4c..5f0bd8a4c 100644 --- a/internal/model/puller.go +++ b/internal/model/puller.go @@ -453,6 +453,8 @@ func (p *Puller) handleFile(file protocol.FileInfo, copyChan chan<- copyBlocksSt FilesAreDifferent: + scanner.PopulateOffsets(file.Blocks) + // Figure out the absolute filenames we need once and for all tempName := filepath.Join(p.dir, defTempNamer.TempName(file.Name)) realName := filepath.Join(p.dir, file.Name) diff --git a/internal/scanner/blocks.go b/internal/scanner/blocks.go index c247fcaaa..9f441b8e6 100644 --- a/internal/scanner/blocks.go +++ b/internal/scanner/blocks.go @@ -68,6 +68,15 @@ func Blocks(r io.Reader, blocksize int, sizehint int64) ([]protocol.BlockInfo, e return blocks, nil } +// Set the Offset field on each block +func PopulateOffsets(blocks []protocol.BlockInfo) { + var offset int64 + for i := range blocks { + blocks[i].Offset = offset + offset += int64(blocks[i].Size) + } +} + // BlockDiff returns lists of common and missing (to transform src into tgt) // blocks. Both block lists must have been created with the same block size. func BlockDiff(src, tgt []protocol.BlockInfo) (have, need []protocol.BlockInfo) { @@ -75,13 +84,6 @@ func BlockDiff(src, tgt []protocol.BlockInfo) (have, need []protocol.BlockInfo) return nil, nil } - // Set the Offset field on each target block - var offset int64 - for i := range tgt { - tgt[i].Offset = offset - offset += int64(tgt[i].Size) - } - if len(tgt) != 0 && len(src) == 0 { // Copy the entire file return nil, tgt