(trunk libT) minor code cleanup to inout.c's readOrWriteBytes().

Use ijuxda's suggestion of making the fstat(fd) call dependent on (fd>=0) rather than (!err).
This commit is contained in:
Jordan Lee 2011-02-02 06:06:09 +00:00
parent fc1c5fe553
commit 4736d863bf
1 changed files with 9 additions and 5 deletions

View 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 ) {