mirror of
https://github.com/transmission/transmission
synced 2025-02-02 20:43:51 +00:00
Truncate files that are too large during initial hash check.
This commit is contained in:
parent
978b5cec11
commit
5a59d210c4
1 changed files with 23 additions and 0 deletions
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue