]> granicus.if.org Git - transmission/commitdiff
#912: Resume file parsed twice on startup
authorCharles Kerr <charles@transmissionbt.com>
Tue, 6 May 2008 01:43:24 +0000 (01:43 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Tue, 6 May 2008 01:43:24 +0000 (01:43 +0000)
gtk/add-dialog.c
libtransmission/torrent.c
libtransmission/verify.c

index 2854510a13808cf33c4aab022c4d8b060905f505..70c66eeee7d02dc1bf0a736f13537290b76e59c3 100644 (file)
@@ -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;
index 9069259ab4993a4b087791414375c15c90064ce0..40e2a12bca542455eb8738bfd1226baa1196fded 100644 (file)
@@ -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 )
 {
index eaf426006d7c32bd4608fb799ae15deb119e6c1e..a190ad6ab9c28700058693b9af970cfc1ce54a1f 100644 (file)
@@ -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; i<tor->info.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 );
         }
     }