]> granicus.if.org Git - transmission/commitdiff
(trunk libT) #3852 "Removing data from an active torrent doesn't stop activity" ...
authorCharles Kerr <charles@transmissionbt.com>
Mon, 27 Dec 2010 21:34:12 +0000 (21:34 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Mon, 27 Dec 2010 21:34:12 +0000 (21:34 +0000)
libtransmission/inout.c
libtransmission/peer-msgs.c

index a9d2fa1319323c7771f7c04d6d884d5ab5786621..1eac6e5455dcab35af8965fa2e2bf94f1ac375d0 100644 (file)
@@ -60,11 +60,11 @@ enum { TR_IO_READ, TR_IO_PREFETCH,
 /* returns 0 on success, or an errno on failure */
 static int
 readOrWriteBytes( tr_session       * session,
-                  const tr_torrent * tor,
+                  tr_torrent       * tor,
                   int                ioMode,
                   tr_file_index_t    fileIndex,
                   uint64_t           fileOffset,
-                  void *             buf,
+                  void             * buf,
                   size_t             buflen )
 {
     const tr_info * info = &tor->info;
@@ -138,6 +138,14 @@ readOrWriteBytes( tr_session       * session,
 
     if( !err )
     {
+        /* 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 );
+            err = ENOENT;
+        }
+
         if( ioMode == TR_IO_READ ) {
             const int rc = tr_pread( fd, buf, buflen, fileOffset );
             if( rc < 0 ) {
@@ -238,7 +246,7 @@ readOrWritePiece( tr_torrent       * tor,
         ++fileIndex;
         fileOffset = 0;
 
-        if( ( err != 0 ) && (ioMode == TR_IO_WRITE ) )
+        if( ( err != 0 ) && (ioMode == TR_IO_WRITE ) && ( tor->error != TR_STAT_LOCAL_ERROR ) )
         {
             char * path = tr_buildPath( tor->downloadDir, file->name, NULL );
             tr_torrentSetLocalError( tor, "%s (%s)", tr_strerror( err ), path );
index f8b5425ee6f93ae91ab9abaeadfbc5ba9669576a..8d6a04d4a60767c70fefb2cd6ad676c209475d7f 100644 (file)
@@ -1907,14 +1907,10 @@ fillOutputBuffer( tr_peermsgs * msgs, time_t now )
             iovec[0].iov_len = req.length;
             evbuffer_commit_space( out, iovec, 1 );
 
-            /* if we couldn't load a piece we thought we could load... */
-            if( err )
-                tr_torrentSetLocalError( msgs->torrent, _( "Couldn't read piece #%zu from disk! Please Verify Local Data." ), (size_t)req.index );
-
             /* check the piece if it needs checking... */
             if( !err && tr_torrentPieceNeedsCheck( msgs->torrent, req.index ) )
                 if(( err = !tr_torrentCheckPiece( msgs->torrent, req.index )))
-                    tr_torrentSetLocalError( msgs->torrent, _( "Piece #%zu is corrupt! Please Verify Local Data." ), (size_t)req.index );
+                    tr_torrentSetLocalError( msgs->torrent, _( "Please Verify Local Data! Piece #%zu is corrupt." ), (size_t)req.index );
 
             if( err )
             {