From 7254a96ce8f9e5ae6793c2010f1af506607412ea Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 13 Aug 2007 16:43:33 +0000 Subject: [PATCH] let fastresume remember which torrents are stopped and which are running. --- libtransmission/fastresume.c | 33 ++++++++++++++++++++++++++++++--- libtransmission/torrent.c | 10 +++++++++- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/libtransmission/fastresume.c b/libtransmission/fastresume.c index 5e51103e2..21d161e81 100644 --- a/libtransmission/fastresume.c +++ b/libtransmission/fastresume.c @@ -92,7 +92,12 @@ enum * uint32_t: ul speed rate to use when the mode is single * uint32_t: ul's tr_speedlimit_t */ - FR_ID_SPEED = 8 + FR_ID_SPEED = 8, + + /* active + * char: 't' if running, 'f' if paused + */ + FR_ID_RUN = 9 }; @@ -148,8 +153,12 @@ getMTimes( const tr_torrent_t * tor, int * setme_n ) return m; } -static void fastResumeWriteData( uint8_t id, void * data, uint32_t size, - uint32_t count, FILE * file ) +static void +fastResumeWriteData( uint8_t id, + const void * data, + uint32_t size, + uint32_t count, + FILE * file ) { uint32_t datalen = size * count; @@ -261,6 +270,11 @@ tr_fastResumeSave( const tr_torrent_t * tor ) tr_free( buf ); } + if( TRUE ) /* FR_ID_RUN */ + { + const char is_running = (tor->runStatus == TR_RUN_RUNNING) ? 't' : 'f'; + fastResumeWriteData( FR_ID_RUN, &is_running, 1, 1, file ); + } /* Write download and upload totals */ total = tor->downloadedCur + tor->downloadedPrev; @@ -556,6 +570,19 @@ fastResumeLoadImpl ( tr_torrent_t * tor, } break; + case FR_ID_RUN: + { + char ch; + if( fread( &ch, 1, 1, file ) != 1 ) + { + fclose( file ); + return ret; + } + tor->runStatus = ch=='f' ? TR_RUN_STOPPED : TR_RUN_RUNNING; + ret |= TR_FR_RUN; + continue; + } + case FR_ID_DOWNLOADED: /* read download total */ if( 8 == len) diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 09ce155f9..53ff9e6fc 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -288,10 +288,18 @@ torrentRealInit( tr_handle_t * h, assert( !tor->uploadedCur ); tor->error = TR_OK; - tor->runStatus = flags & TR_FLAG_PAUSED ? TR_RUN_STOPPED : TR_RUN_RUNNING; uncheckedPieces = tr_bitfieldNew( tor->info.pieceCount ); loaded = tr_fastResumeLoad( tor, uncheckedPieces ); + + /* the `paused' flag has highest precedence... + after that, the fastresume setting is used... + if that's not found, default to RUNNING */ + if( flags & TR_FLAG_PAUSED ) + tor->runStatus = TR_RUN_STOPPED; + else if( !(loaded & TR_FR_RUN ) ) + tor->runStatus = TR_RUN_RUNNING; + if( tr_bitfieldIsEmpty( uncheckedPieces ) ) tr_bitfieldFree( uncheckedPieces ); else