Changeset 1608


Ignore:
Timestamp:
Mar 30, 2007, 5:35:23 PM (15 years ago)
Author:
joshe
Message:

Truncate files that are too large during initial hash check.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/inout.c

    r1420 r1608  
    223223    uint8_t * buf;
    224224    uint8_t hash[SHA_DIGEST_LENGTH];
     225    struct stat sb;
    225226
    226227    io->pieceSlot = malloc( inf->pieceCount * sizeof( int ) );
     
    237238    memset( io->pieceSlot, 0xFF, inf->pieceCount * sizeof( int ) );
    238239    memset( io->slotPiece, 0xFF, inf->pieceCount * sizeof( int ) );
     240
     241    /* Truncate files that are too large */
     242    for( i = 0; inf->fileCount > i; i++ )
     243    {
     244        if( 0 > stat( inf->files[i].name, &sb ) )
     245        {
     246            if( ENOENT == errno )
     247            {
     248                continue;
     249            }
     250            tr_err( "Could not stat %s (%s)",
     251                    inf->files[i].name, strerror( errno ) );
     252            break;
     253        }
     254
     255        if( sb.st_size > ( off_t )inf->files[i].length )
     256        {
     257            tr_dbg( "truncate %s from %"PRIu64" to %"PRIu64" bytes",
     258                    inf->files[i].name, sb.st_size, inf->files[i].length );
     259            truncate( inf->files[i].name, inf->files[i].length );
     260        }
     261    }
    239262
    240263    /* Check pieces */
Note: See TracChangeset for help on using the changeset viewer.