]> granicus.if.org Git - transmission/commitdiff
(trunk libT) minor code cleanup to inout.c's readOrWriteBytes().
authorJordan Lee <jordan@transmissionbt.com>
Wed, 2 Feb 2011 06:06:09 +0000 (06:06 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Wed, 2 Feb 2011 06:06:09 +0000 (06:06 +0000)
Use ijuxda's suggestion of making the fstat(fd) call dependent on (fd>=0) rather than (!err).

libtransmission/inout.c

index 7e24d1c843b149201c06491c6d74658fd330ebf8..c611dea4dd7f9982185eef00652a00ccd9905d10 100644 (file)
@@ -136,16 +136,20 @@ readOrWriteBytes( tr_session       * session,
         tr_free( subpath );
     }
 
-    if( !err )
+    /* check that the file corresponding to 'fd' still exists */
+    if( fd >= 0 )
     {
-        /* check & see if someone deleted the file while it was in our cache */
         struct stat sb;
-        const tr_bool file_disappeared = fstat( fd, &sb ) || sb.st_nlink < 1;
-        if( file_disappeared ) {
-            tr_torrentSetLocalError( tor, "Please Verify Local Data! A file disappeared: \"%s\"", tor->info.files[fileIndex].name );
+
+        if( !fstat( fd, &sb ) && sb.st_nlink < 1 )
+        {
+            tr_torrentSetLocalError( tor, "Please Verify Local Data! A file disappeared: \"%s\"", file->name );
             err = ENOENT;
         }
+    }
 
+    if( !err )
+    {
         if( ioMode == TR_IO_READ ) {
             const int rc = tr_pread( fd, buf, buflen, fileOffset );
             if( rc < 0 ) {