1
0
mirror of https://github.com/gilbertchen/duplicacy synced 2025-12-15 07:43:21 +00:00

Check -files may download a chunk multple times

This commit fixed a bug that caused 'check -files' to download the same chunk
multiple times if shared by multiple small files.
This commit is contained in:
Gilbert Chen
2019-06-13 14:47:21 -04:00
parent 41668d4bbd
commit 4da7f7b6f9
2 changed files with 14 additions and 3 deletions

View File

@@ -197,6 +197,16 @@ func (downloader *ChunkDownloader) Reclaim(chunkIndex int) {
downloader.lastChunkIndex = chunkIndex downloader.lastChunkIndex = chunkIndex
} }
// Return the chunk last downloaded and its hash
func (downloader *ChunkDownloader) GetLastDownloadedChunk() (chunk *Chunk, chunkHash string) {
if downloader.lastChunkIndex >= len(downloader.taskList) {
return nil, ""
}
task := downloader.taskList[downloader.lastChunkIndex]
return task.chunk, task.chunkHash
}
// WaitForChunk waits until the specified chunk is ready // WaitForChunk waits until the specified chunk is ready
func (downloader *ChunkDownloader) WaitForChunk(chunkIndex int) (chunk *Chunk) { func (downloader *ChunkDownloader) WaitForChunk(chunkIndex int) (chunk *Chunk) {

View File

@@ -1194,7 +1194,6 @@ func (manager *SnapshotManager) RetrieveFile(snapshot *Snapshot, file *Entry, ou
} }
var chunk *Chunk var chunk *Chunk
currentHash := ""
for i := file.StartChunk; i <= file.EndChunk; i++ { for i := file.StartChunk; i <= file.EndChunk; i++ {
start := 0 start := 0
@@ -1207,10 +1206,12 @@ func (manager *SnapshotManager) RetrieveFile(snapshot *Snapshot, file *Entry, ou
} }
hash := snapshot.ChunkHashes[i] hash := snapshot.ChunkHashes[i]
if currentHash != hash { lastChunk, lastChunkHash := manager.chunkDownloader.GetLastDownloadedChunk()
if lastChunkHash != hash {
i := manager.chunkDownloader.AddChunk(hash) i := manager.chunkDownloader.AddChunk(hash)
chunk = manager.chunkDownloader.WaitForChunk(i) chunk = manager.chunkDownloader.WaitForChunk(i)
currentHash = hash } else {
chunk = lastChunk
} }
output(chunk.GetBytes()[start:end]) output(chunk.GetBytes()[start:end])