(trunk libT) #3852 "Removing data from an active torrent doesn't stop activity" -- possible fix.

This commit is contained in:
Charles Kerr 2010-12-27 21:34:12 +00:00
parent e5bb3205a1
commit c011fe527b
2 changed files with 12 additions and 8 deletions

View File

@ -60,11 +60,11 @@ enum { TR_IO_READ, TR_IO_PREFETCH,
/* returns 0 on success, or an errno on failure */ /* returns 0 on success, or an errno on failure */
static int static int
readOrWriteBytes( tr_session * session, readOrWriteBytes( tr_session * session,
const tr_torrent * tor, tr_torrent * tor,
int ioMode, int ioMode,
tr_file_index_t fileIndex, tr_file_index_t fileIndex,
uint64_t fileOffset, uint64_t fileOffset,
void * buf, void * buf,
size_t buflen ) size_t buflen )
{ {
const tr_info * info = &tor->info; const tr_info * info = &tor->info;
@ -138,6 +138,14 @@ readOrWriteBytes( tr_session * session,
if( !err ) 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 ) { if( ioMode == TR_IO_READ ) {
const int rc = tr_pread( fd, buf, buflen, fileOffset ); const int rc = tr_pread( fd, buf, buflen, fileOffset );
if( rc < 0 ) { if( rc < 0 ) {
@ -238,7 +246,7 @@ readOrWritePiece( tr_torrent * tor,
++fileIndex; ++fileIndex;
fileOffset = 0; 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 ); char * path = tr_buildPath( tor->downloadDir, file->name, NULL );
tr_torrentSetLocalError( tor, "%s (%s)", tr_strerror( err ), path ); tr_torrentSetLocalError( tor, "%s (%s)", tr_strerror( err ), path );

View File

@ -1907,14 +1907,10 @@ fillOutputBuffer( tr_peermsgs * msgs, time_t now )
iovec[0].iov_len = req.length; iovec[0].iov_len = req.length;
evbuffer_commit_space( out, iovec, 1 ); 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... */ /* check the piece if it needs checking... */
if( !err && tr_torrentPieceNeedsCheck( msgs->torrent, req.index ) ) if( !err && tr_torrentPieceNeedsCheck( msgs->torrent, req.index ) )
if(( err = !tr_torrentCheckPiece( 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 ) if( err )
{ {