]> granicus.if.org Git - transmission/commitdiff
(trunk libT) #3973 "JIT verification verifies fresh downloaded torrents" -- improveme...
authorJordan Lee <jordan@transmissionbt.com>
Wed, 2 Feb 2011 23:29:17 +0000 (23:29 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Wed, 2 Feb 2011 23:29:17 +0000 (23:29 +0000)
r11813 fixed the timestamp issue by fsync()ing files before close()ing them in tr_close_file(). This causes a little overhead as even read-only files cause a sync as their atimes are modified. Instead, we should call fsync() further back in the call chain in tr_fdFileClose() so that we can know to only sync torrent files that were opened with write access.

libtransmission/fdlimit.c
libtransmission/fdlimit.h

index 9eae214d60b31d656e85541cb758128e2a676c20..e9dd9d0eb803a42410d79f693937dcba8417bcdf 100644 (file)
@@ -308,7 +308,6 @@ tr_close_file( int fd )
      * but it couldn't hurt... */
     fcntl( fd, F_NOCACHE, 1 );
 #endif
-    tr_fsync( fd );
     close( fd );
 }
 
@@ -526,7 +525,14 @@ tr_fdFileClose( tr_session * s, const tr_torrent * tor, tr_file_index_t i )
     struct tr_cached_file * o;
 
     if(( o = fileset_lookup( get_fileset( s ), tr_torrentId( tor ), i )))
+    {
+        /* flush writable files so that their mtimes will be
+         * up-to-date when this function returns to the caller... */
+        if( o->is_writable )
+            tr_fsync( o->fd );
+
         cached_file_close( o );
+    }
 }
 
 int
index d03bf4b2390d38771b47bb702ff57022d9dbf4e2..4ecf9012718f2162108a46f980cbb2ad855e8cf7 100644 (file)
@@ -78,7 +78,7 @@ int tr_fdFileGetCached( tr_session             * session,
 /**
  * Closes a file that's being held by our file repository.
  *
- * If the file isn't checked out, it's closed immediately.
+ * If the file isn't checked out, it's fsync()ed and close()d immediately.
  * If the file is currently checked out, it will be closed upon its return.
  *
  * @see tr_fdFileCheckout