From 05bcd5e01cd2ec5dd5b867d5c68dd7067fec8bb0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 13 Oct 2007 03:58:54 +0000 Subject: [PATCH] fix r3379 bug that forced us to recheck the torrents every startup --- libtransmission/fastresume.c | 25 ++++++++++++++++--------- libtransmission/fastresume.h | 5 +++-- libtransmission/torrent.c | 8 +------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/libtransmission/fastresume.c b/libtransmission/fastresume.c index 1dcf0499a..60d915262 100644 --- a/libtransmission/fastresume.c +++ b/libtransmission/fastresume.c @@ -194,6 +194,13 @@ tr_fastResumeSave( const tr_torrent * tor ) /* Write format version */ fwrite( &version, 4, 1, file ); + if( TRUE ) /* FR_ID_DESTINATION */ + { + const char * d = tor->destination ? tor->destination : ""; + const int byteCount = strlen( d ) + 1; + fastResumeWriteData( FR_ID_DESTINATION, d, 1, byteCount, file ); + } + /* Write progress data */ if (1) { int n; @@ -285,13 +292,6 @@ tr_fastResumeSave( const tr_torrent * tor ) fastResumeWriteData( FR_ID_RUN, &is_running, 1, 1, file ); } - if( TRUE ) /* FR_ID_DESTINATION */ - { - const char * d = tor->destination ? tor->destination : ""; - const int byteCount = strlen( d ) + 1; - fastResumeWriteData( FR_ID_DESTINATION, d, 1, byteCount, file ); - } - /* Write download and upload totals */ total = tor->downloadedCur + tor->downloadedPrev; @@ -513,6 +513,7 @@ fastResumeLoadOld( tr_torrent * tor, static uint64_t fastResumeLoadImpl ( tr_torrent * tor, + const char * fallbackDestination, tr_bitfield * uncheckedPieces ) { char path[MAX_PATH_LENGTH]; @@ -561,6 +562,7 @@ fastResumeLoadImpl ( tr_torrent * tor, /* read each block of data */ while( 1 == fread( &id, 1, 1, file ) && 1 == fread( &len, 4, 1, file ) ) { +fprintf( stderr, "reading id %d\n", (int)id ); switch( id ) { case FR_ID_PROGRESS: @@ -625,7 +627,10 @@ fastResumeLoadImpl ( tr_torrent * tor, return ret; } - ret |= TR_FR_DESTINATION;; + if( tor->destination == NULL ) + tor->destination = tr_strdup( fallbackDestination ); + + ret |= TR_FR_DESTINATION; continue; } break; @@ -740,6 +745,7 @@ fastResumeLoadImpl ( tr_torrent * tor, tr_inf( "Skipping resume data type %02x, %u bytes", id, len ); fseek( file, len, SEEK_CUR ); } +fprintf( stderr, "\n\n" ); fclose( file ); return ret; @@ -747,9 +753,10 @@ fastResumeLoadImpl ( tr_torrent * tor, uint64_t tr_fastResumeLoad( tr_torrent * tor, + const char * fallbackDestination, tr_bitfield * uncheckedPieces ) { - const uint64_t ret = fastResumeLoadImpl( tor, uncheckedPieces ); + const uint64_t ret = fastResumeLoadImpl( tor, fallbackDestination, uncheckedPieces ); if( ! ( ret & TR_FR_PROGRESS ) ) tr_bitfieldAddRange( uncheckedPieces, 0, tor->info.pieceCount ); diff --git a/libtransmission/fastresume.h b/libtransmission/fastresume.h index 7c6951805..cc3a777b6 100644 --- a/libtransmission/fastresume.h +++ b/libtransmission/fastresume.h @@ -43,7 +43,8 @@ enum /** * Returns a bitwise-or'ed set of the data loaded from fastresume */ -uint64_t tr_fastResumeLoad( tr_torrent * tor, - struct tr_bitfield * uncheckedPieces ); +uint64_t tr_fastResumeLoad( tr_torrent * tor, + const char * fallbackDestination, + struct tr_bitfield * uncheckedPieces ); #endif diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 993bc887a..d1d3c980b 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -338,14 +338,8 @@ torrentRealInit( tr_handle * h, tor->error = TR_OK; uncheckedPieces = tr_bitfieldNew( tor->info.pieceCount ); - loaded = tr_fastResumeLoad( tor, uncheckedPieces ); - /* a path passed in by the user overrides - the one loaded by fastresume... */ - if( destination && *destination ) { - tr_free( tor->destination ); - tor->destination = tr_strdup( destination ); - } + loaded = tr_fastResumeLoad( tor, destination, uncheckedPieces ); /* the `paused' flag has highest precedence... after that, the fastresume setting is used...