(libT) eliminating tr_errno, part 1: make tr_ioTestPiece return an int instead of a tr_errno.

This commit is contained in:
Charles Kerr 2008-10-02 20:30:29 +00:00
parent 262370f7ea
commit 79d8a5cdf3
4 changed files with 14 additions and 29 deletions

View File

@ -266,22 +266,12 @@ recalculateHash( const tr_torrent * tor,
return err;
}
tr_errno
int
tr_ioTestPiece( const tr_torrent * tor,
int pieceIndex )
{
int err;
uint8_t hash[SHA_DIGEST_LENGTH];
err = recalculateHash( tor, pieceIndex, hash );
if( !err && memcmp( hash, tor->info.pieces[pieceIndex].hash,
SHA_DIGEST_LENGTH ) )
err = TR_ERROR_IO_CHECKSUM;
tr_tordbg ( tor, "piece %d hash check: %s",
pieceIndex, ( err ? "FAILED" : "OK" ) );
return err;
const tr_errno err = recalculateHash( tor, pieceIndex, hash );
return !err && !memcmp( hash, tor->info.pieces[pieceIndex].hash, SHA_DIGEST_LENGTH );
}

View File

@ -50,12 +50,10 @@ tr_errno tr_ioWrite( const struct tr_torrent * tor,
const uint8_t * writeme );
/**
* returns 0 if the piece matches its metainfo's SHA1 checksum,
* or TR_ERROR_IO_* if there was a problem reading the piece,
* or TR_ERROR if the checksum didn't match.
* returns nonzero if the piece matches its metainfo's SHA1 checksum.
*/
tr_errno tr_ioTestPiece( const tr_torrent*,
int piece );
int tr_ioTestPiece( const tr_torrent*,
int piece );
/**

View File

@ -959,22 +959,20 @@ peerCallbackFunc( void * vpeer,
if( tr_cpPieceIsComplete( tor->completion, e->pieceIndex ) )
{
const tr_piece_index_t p = e->pieceIndex;
const tr_errno err = tr_ioTestPiece( tor, p );
const int ok = tr_ioTestPiece( tor, p );
if( err )
if( !ok )
{
tr_torerr( tor,
_(
"Piece %lu, which was just downloaded, failed its checksum test: %s" ),
(unsigned long)p, tr_errorString( err ) );
_( "Piece %lu, which was just downloaded, failed its checksum test" ),
(unsigned long)p );
}
tr_torrentSetHasPiece( tor, p, !err );
tr_torrentSetHasPiece( tor, p, ok );
tr_torrentSetPieceChecked( tor, p, TRUE );
tr_peerMgrSetBlame( tor->session->peerMgr, tor->info.hash, p,
!err );
tr_peerMgrSetBlame( tor->session->peerMgr, tor->info.hash, p, ok );
if( err )
if( !ok )
gotBadPiece( t, p );
else
{

View File

@ -85,9 +85,8 @@ checkFile( tr_torrent * tor,
{
const int wasComplete = tr_cpPieceIsComplete(
tor->completion, i );
const tr_errno err = tr_ioTestPiece( tor, i );
if( !err ) /* yay */
if( tr_ioTestPiece( tor, i ) ) /* yay */
{
tr_torrentSetHasPiece( tor, i, TRUE );
if( !wasComplete )