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
}
// 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) {