From 8f0487b9d307b8ec4cf10b512e0710f75247ccdc Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 14 Apr 2010 00:34:31 +0000 Subject: [PATCH] (trunk libT) in seedRatio, handle the case where a file is downloaded more than once --- libtransmission/torrent.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index b63322b62..12425db12 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -288,16 +288,20 @@ tr_torrentGetSeedRatio( const tr_torrent * tor, double * ratio ) /* returns true if the seed ratio applies -- * it applies if the torrent's a seed AND it has a seed ratio set */ static tr_bool -tr_torrentGetSeedRatioBytes( tr_torrent * tor, uint64_t * setmeLeft, uint64_t * setmeGoal ) +tr_torrentGetSeedRatioBytes( tr_torrent * tor, + uint64_t * setmeLeft, + uint64_t * setmeGoal ) { double seedRatio; tr_bool seedRatioApplies = FALSE; if( tr_torrentGetSeedRatio( tor, &seedRatio ) ) { - const uint64_t upEver = tor->uploadedCur + tor->uploadedPrev; - const uint64_t goal = seedRatio * tr_cpSizeWhenDone ( &tor->completion ); - if( setmeLeft ) *setmeLeft = goal > upEver ? goal - upEver : 0; + const uint64_t u = tor->uploadedCur + tor->uploadedPrev; + const uint64_t d = tor->downloadedCur + tor->downloadedPrev; + const uint64_t baseline = d ? d : tr_cpSizeWhenDone( &tor->completion ); + const uint64_t goal = baseline * seedRatio; + if( setmeLeft ) *setmeLeft = goal > u ? goal - u : 0; if( setmeGoal ) *setmeGoal = goal; seedRatioApplies = tr_torrentIsSeed( tor ); } -- 2.40.0