Skip to content

Commit

Permalink
Check -files may download a chunk multple times
Browse files Browse the repository at this point in the history
This commit fixed a bug that caused 'check -files' to download the same chunk
multiple times if shared by multiple small files.
  • Loading branch information
gilbertchen committed Jun 13, 2019
1 parent 41668d4 commit 4da7f7b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/duplicacy_chunkdownloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ func (downloader *ChunkDownloader) Reclaim(chunkIndex int) {
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
func (downloader *ChunkDownloader) WaitForChunk(chunkIndex int) (chunk *Chunk) {

Expand Down
7 changes: 4 additions & 3 deletions src/duplicacy_snapshotmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,6 @@ func (manager *SnapshotManager) RetrieveFile(snapshot *Snapshot, file *Entry, ou
}

var chunk *Chunk
currentHash := ""

for i := file.StartChunk; i <= file.EndChunk; i++ {
start := 0
Expand All @@ -1207,10 +1206,12 @@ func (manager *SnapshotManager) RetrieveFile(snapshot *Snapshot, file *Entry, ou
}

hash := snapshot.ChunkHashes[i]
if currentHash != hash {
lastChunk, lastChunkHash := manager.chunkDownloader.GetLastDownloadedChunk()
if lastChunkHash != hash {
i := manager.chunkDownloader.AddChunk(hash)
chunk = manager.chunkDownloader.WaitForChunk(i)
currentHash = hash
} else {
chunk = lastChunk
}

output(chunk.GetBytes()[start:end])
Expand Down

1 comment on commit 4da7f7b

@gilbertchen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Duplicacy Forum. There might be relevant details there:

https://forum.duplicacy.com/t/duplicacy-check-taking-unreasonably-long-time/2231/6

Please sign in to comment.