From ed4e9024820f21c92c5a8ccec5bf1870a1967a46 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 6 May 2008 01:43:24 +0000 Subject: [PATCH] #912: Resume file parsed twice on startup --- gtk/add-dialog.c | 4 ++-- libtransmission/torrent.c | 26 +++++++++++++++++++------- libtransmission/verify.c | 18 ++++++++++++++---- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/gtk/add-dialog.c b/gtk/add-dialog.c index 2854510a1..70c66eeee 100644 --- a/gtk/add-dialog.c +++ b/gtk/add-dialog.c @@ -205,11 +205,11 @@ addSingleTorrentDialog( GtkWindow * parent, gtk_table_attach( GTK_TABLE( t ), w, col, col+1, row, row+1, ~0, 0, 0, 0 ); gtk_label_set_mnemonic_widget( GTK_LABEL( l ), w ); addTorrentFilters( GTK_FILE_CHOOSER( w ) ); - g_signal_connect( w, "selection-changed", - G_CALLBACK( sourceChanged ), data ); if( data->filename ) if( !gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( w ), data->filename ) ) g_warning( "couldn't select '%s'", data->filename ); + g_signal_connect( w, "selection-changed", + G_CALLBACK( sourceChanged ), data ); ++row; col = 0; diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 9069259ab..40e2a12bc 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -357,6 +357,8 @@ randomizeTiers( tr_info * info ) tr_free( r ); } +static void torrentStart( tr_torrent * tor, int reloadProgress ); + static void torrentRealInit( tr_handle * h, tr_torrent * tor, @@ -477,7 +479,7 @@ torrentRealInit( tr_handle * h, tr_metainfoMigrate( h, &tor->info ); if( doStart ) - tr_torrentStart( tor ); + torrentStart( tor, FALSE ); } static int @@ -550,9 +552,12 @@ tr_torrentNew( tr_handle * handle, void tr_torrentSetFolder( tr_torrent * tor, const char * path ) { - tr_free( tor->destination ); - tor->destination = tr_strdup( path ); - tr_torrentSaveResume( tor ); + if( !path || !tor->destination || strcmp( path, tor->destination ) ) + { + tr_free( tor->destination ); + tor->destination = tr_strdup( path ); + tr_torrentSaveResume( tor ); + } } const char* @@ -998,14 +1003,15 @@ checkAndStartCB( tr_torrent * tor ) tr_runInEventThread( tor->handle, checkAndStartImpl, tor ); } -void -tr_torrentStart( tr_torrent * tor ) +static void +torrentStart( tr_torrent * tor, int reloadProgress ) { tr_globalLock( tor->handle ); if( !tor->isRunning ) { - tr_torrentLoadResume( tor, TR_FR_PROGRESS, NULL ); + if( reloadProgress ) + tr_torrentLoadResume( tor, TR_FR_PROGRESS, NULL ); tor->isRunning = 1; tr_verifyAdd( tor, checkAndStartCB ); } @@ -1013,6 +1019,12 @@ tr_torrentStart( tr_torrent * tor ) tr_globalUnlock( tor->handle ); } +void +tr_torrentStart( tr_torrent * tor ) +{ + torrentStart( tor, TRUE ); +} + static void torrentRecheckDoneImpl( void * vtor ) { diff --git a/libtransmission/verify.c b/libtransmission/verify.c index eaf426006..a190ad6ab 100644 --- a/libtransmission/verify.c +++ b/libtransmission/verify.c @@ -56,12 +56,13 @@ static tr_lock* getVerifyLock( void ) return lock; } -static void +static int checkFile( tr_torrent * tor, tr_file_index_t fileIndex, int * abortFlag ) { tr_piece_index_t i; + int changed = FALSE; int nofile; struct stat sb; char path[MAX_PATH_LENGTH]; @@ -78,11 +79,14 @@ checkFile( tr_torrent * tor, } else if( !tr_torrentIsPieceChecked( tor, i ) ) { + const int wasComplete = tr_cpPieceIsComplete( tor->completion, i ); const tr_errno err = tr_ioTestPiece( tor, i ); if( !err ) /* yay */ { tr_torrentSetHasPiece( tor, i, TRUE ); + if( !wasComplete ) + changed = TRUE; } else { @@ -91,13 +95,17 @@ checkFile( tr_torrent * tor, * it being incomplete, do nothing -- we don't * want to lose blocks in those incomplete pieces */ - if( tr_cpPieceIsComplete( tor->completion, i ) ) + if( wasComplete ) { tr_torrentSetHasPiece( tor, i, FALSE ); + changed = TRUE; + } } } tr_torrentSetPieceChecked( tor, i, TRUE ); } + + return changed; } static void @@ -105,6 +113,7 @@ verifyThreadFunc( void * unused UNUSED ) { for( ;; ) { + int changed = 0; tr_file_index_t i; tr_torrent * tor; struct verify_node * node; @@ -127,13 +136,14 @@ verifyThreadFunc( void * unused UNUSED ) tr_torinf( tor, _( "Verifying torrent" ) ); for( i=0; iinfo.fileCount && !stopCurrent; ++i ) - checkFile( tor, i, &stopCurrent ); + changed |= checkFile( tor, i, &stopCurrent ); tor->verifyState = TR_VERIFY_NONE; if( !stopCurrent ) { - tr_torrentSaveResume( tor ); + if( changed ) + tr_torrentSaveResume( tor ); fireCheckDone( tor, currentNode.verify_done_cb ); } } -- 2.40.0