diff --git a/libtransmission/completion.c b/libtransmission/completion.c index ecea5ff79..d44d3c769 100644 --- a/libtransmission/completion.c +++ b/libtransmission/completion.c @@ -97,13 +97,29 @@ tr_cpSizeWhenDone( const tr_completion * ccp ) if( ccp->sizeWhenDoneIsDirty ) { tr_completion * cp = (tr_completion *) ccp; /* mutable */ - const tr_info * info = &cp->tor->info; + const tr_torrent * tor = cp->tor; + const tr_info * info = &tor->info; tr_piece_index_t i; uint64_t size = 0; for( i=0; ipieceCount; ++i ) - if( !info->pieces[i].dnd || tr_cpPieceIsComplete( cp, i ) ) - size += tr_torPieceCountBytes( cp->tor, i ); + { + if( !info->pieces[i].dnd ) { + // we want the piece... + size += tr_torPieceCountBytes( tor, i ); + } else if( tr_cpPieceIsComplete( cp, i ) ) { + // we have the piece... + size += tr_torPieceCountBytes( tor, i ); + } else if( cp->completeBlocks[i] ) { + // we have part of the piece... + const tr_block_index_t b = tr_torPieceFirstBlock( tor, i ); + const tr_block_index_t e = b + tr_torPieceCountBlocks( tor, i ); + tr_block_index_t j; + for( j=b; jsizeWhenDoneLazy = size; cp->sizeWhenDoneIsDirty = 0;