]> granicus.if.org Git - transmission/commitdiff
(trunk libT) #3973 "JIT verification verifies freshly-downloaded torrents" -- test...
authorJordan Lee <jordan@transmissionbt.com>
Wed, 2 Feb 2011 20:30:04 +0000 (20:30 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Wed, 2 Feb 2011 20:30:04 +0000 (20:30 +0000)
Files downloaded in Transmission 2.20 betas [1..3] forced each piece to be checked twice -- once on download, and once when uploading the piece for the first time. Older versions of Transmission didn't perform the latter check unless the file had changed after it was downloaded. This commit restores that behavior.

libtransmission/fdlimit.c
libtransmission/torrent.c

index 480eab51d74e0662f63229ba082a711d7b4e7d44..030355132f7df5f005f264dde9f1489e5f3ebffc 100644 (file)
@@ -295,6 +295,7 @@ tr_close_file( int fd )
      * but it couldn't hurt... */
     fcntl( fd, F_NOCACHE, 1 );
 #endif
+    fsync( fd );
     close( fd );
 }
 
index 9ba64f04057c81ad81584b253f4023a74243be48..b9aba8abd68ac23e5f339d1f2c721cbcee474b0a 100644 (file)
@@ -2951,21 +2951,30 @@ tr_torrentFileCompleted( tr_torrent * tor, tr_file_index_t fileNum )
 {
     char * sub;
     const char * base;
+    const tr_info * inf = &tor->info;
+    const tr_file * f = &inf->files[fileNum];
+    tr_piece * p;
+    const tr_piece * pend;
+    const time_t now = tr_time( );
 
     /* close the file so that we can reopen in read-only mode as needed */
     tr_fdFileClose( tor->session, tor, fileNum );
 
+    /* now that the file is complete and closed, we can start watching its
+     * mtime timestamp for changes to know if we need to reverify pieces */
+    fprintf( stderr, "file %d completed.. setting all files' timestamps to %zu (%s)\n", (int)fileNum, (size_t)now, f->name );
+    for( p=&inf->pieces[f->firstPiece], pend=&inf->pieces[f->lastPiece]; p!=pend; ++p )
+        p->timeChecked = now;
+
     /* if the torrent's current filename isn't the same as the one in the
      * metadata -- for example, if it had the ".part" suffix appended to
      * it until now -- then rename it to match the one in the metadata */
     if( tr_torrentFindFile2( tor, fileNum, &base, &sub ) )
     {
-        const tr_file * file = &tor->info.files[fileNum];
-
-        if( strcmp( sub, file->name ) )
+        if( strcmp( sub, f->name ) )
         {
             char * oldpath = tr_buildPath( base, sub, NULL );
-            char * newpath = tr_buildPath( base, file->name, NULL );
+            char * newpath = tr_buildPath( base, f->name, NULL );
 
             if( rename( oldpath, newpath ) )
                 tr_torerr( tor, "Error moving \"%s\" to \"%s\": %s", oldpath, newpath, tr_strerror( errno ) );