]> granicus.if.org Git - transmission/commitdiff
(trunk libT) #2955 "lazy torrent verification" -- speed up setLocalErrorIfFilesDisapp...
authorCharles Kerr <charles@transmissionbt.com>
Fri, 17 Dec 2010 14:57:19 +0000 (14:57 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Fri, 17 Dec 2010 14:57:19 +0000 (14:57 +0000)
libtransmission/torrent.c

index d64fa2c8dc5958d320336e326cd6e31c1db3f354..57a2ef53d4347be0c5f03119cad186ef8d2976e4 100644 (file)
@@ -737,10 +737,31 @@ tr_torrentGotNewInfoDict( tr_torrent * tor )
     tr_torrentFireMetadataCompleted( tor );
 }
 
+static tr_bool
+hasAnyLocalData( const tr_torrent * tor )
+{
+    tr_file_index_t i;
+    tr_bool has_local_data = FALSE;
+    const tr_file_index_t n = tor->info.fileCount;
+
+    for( i=0; i<n && !has_local_data; ++i )
+    {
+        struct stat sb;
+        char * filename = tr_torrentFindFile( tor, i );
+
+        if( filename && !stat( filename, &sb ) )
+            has_local_data = TRUE;
+
+        tr_free( filename );
+    }
+
+    return has_local_data;
+}
+
 static tr_bool
 setLocalErrorIfFilesDisappeared( tr_torrent * tor )
 {
-    const tr_bool disappeared = ( tr_cpHaveTotal( &tor->completion ) > 0 ) && ( tr_torrentGetCurrentSizeOnDisk( tor ) == 0 );
+    const tr_bool disappeared = ( tr_cpHaveTotal( &tor->completion ) > 0 ) && !hasAnyLocalData( tor );
 
     if( disappeared )
     {