From 23a2d91608e3c28652732e59c0f3d8eb1fa07c31 Mon Sep 17 00:00:00 2001 From: Gilbert Chen Date: Sat, 28 Apr 2018 20:19:24 -0400 Subject: [PATCH] Skipped chunks should not be counted in order to get accurate download percentage --- src/duplicacy_chunkdownloader.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/duplicacy_chunkdownloader.go b/src/duplicacy_chunkdownloader.go index 1647157..b870f96 100644 --- a/src/duplicacy_chunkdownloader.go +++ b/src/duplicacy_chunkdownloader.go @@ -174,7 +174,7 @@ func (downloader *ChunkDownloader) Prefetch(file *Entry) { // Reclaim releases the downloaded chunk to the chunk pool func (downloader *ChunkDownloader) Reclaim(chunkIndex int) { - if downloader.lastChunkIndex == chunkIndex { + if downloader.lastChunkIndex >= chunkIndex { return } @@ -187,13 +187,20 @@ func (downloader *ChunkDownloader) Reclaim(chunkIndex int) { } } + for i := downloader.lastChunkIndex; i < chunkIndex; i++ { + // These chunks are never downloaded if 'isDownloading' is false; note that 'isDownloading' isn't reset to + // false after a chunk has been downloaded + if !downloader.taskList[i].isDownloading { + atomic.AddInt64(&downloader.totalChunkSize, -int64(downloader.taskList[i].chunkLength)) + } + } downloader.lastChunkIndex = chunkIndex } // WaitForChunk waits until the specified chunk is ready func (downloader *ChunkDownloader) WaitForChunk(chunkIndex int) (chunk *Chunk) { - // Reclain any chunk not needed + // Reclaim any chunk not needed downloader.Reclaim(chunkIndex) // If we haven't started download the specified chunk, download it now