Truncate files that are too large during initial hash check.

This commit is contained in:
Josh Elsasser 2007-03-30 17:35:23 +00:00
parent 978b5cec11
commit 5a59d210c4
1 changed files with 23 additions and 0 deletions

View File

@ -222,6 +222,7 @@ static int checkFiles( tr_io_t * io )
int i;
uint8_t * buf;
uint8_t hash[SHA_DIGEST_LENGTH];
struct stat sb;
io->pieceSlot = malloc( inf->pieceCount * sizeof( int ) );
io->slotPiece = malloc( inf->pieceCount * sizeof( int ) );
@ -237,6 +238,28 @@ static int checkFiles( tr_io_t * io )
memset( io->pieceSlot, 0xFF, inf->pieceCount * sizeof( int ) );
memset( io->slotPiece, 0xFF, inf->pieceCount * sizeof( int ) );
/* Truncate files that are too large */
for( i = 0; inf->fileCount > i; i++ )
{
if( 0 > stat( inf->files[i].name, &sb ) )
{
if( ENOENT == errno )
{
continue;
}
tr_err( "Could not stat %s (%s)",
inf->files[i].name, strerror( errno ) );
break;
}
if( sb.st_size > ( off_t )inf->files[i].length )
{
tr_dbg( "truncate %s from %"PRIu64" to %"PRIu64" bytes",
inf->files[i].name, sb.st_size, inf->files[i].length );
truncate( inf->files[i].name, inf->files[i].length );
}
}
/* Check pieces */
io->slotsUsed = 0;
buf = malloc( inf->pieceSize );