Changeset 46


Ignore:
Timestamp:
Jan 24, 2006, 7:01:42 AM (15 years ago)
Author:
joshe
Message:

Add backwards compatibility to read version 0 resume files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/oneport/libtransmission/fastresume.h

    r45 r46  
    153153   
    154154    FILE    * file;
    155     int       version = 1;
     155    int       version = 0;
    156156    char    * path;
    157157    int     * fileMTimes1, * fileMTimes2;
     
    159159    uint8_t * blockBitfield;
    160160
    161     int size;
     161    int sizes[2];
     162    long filesize;
    162163
    163164    /* Open resume file */
     
    173174
    174175    /* Check the size */
    175     size = 4 + 8 + 8 + 4 * inf->fileCount + 4 * inf->pieceCount +
    176         ( tor->blockCount + 7 ) / 8;
     176    sizes[1] = 4 + 8 + 8 + 4 * inf->fileCount + 4 * inf->pieceCount +
     177      ( tor->blockCount + 7 ) / 8;
     178    sizes[0] = sizes[1] - 8 - 8;
    177179    fseek( file, 0, SEEK_END );
    178     if( ftell( file ) != size )
    179     {
    180         tr_inf( "Wrong size for resume file (%d bytes, %d expected)",
    181                 ftell( file ), size );
    182         fclose( file );
    183         return 1;
    184     }
    185     fseek( file, 0, SEEK_SET );
     180    filesize = ftell( file );
     181    if( 4 > filesize )
     182    {
     183        tr_inf( "Wrong size for resume file (%d bytes, at least 4 expected)",
     184                filesize );
     185        fclose( file );
     186        return 1;
     187    }
    186188
    187189    /* Check format version */
    188190    fread( &version, 4, 1, file );
    189     if( version != 0 )
     191    if( 0 > version || 1 < version )
    190192    {
    191193        tr_inf( "Resume file has version %d, not supported",
     
    195197    }
    196198
    197     /* read download and upload totals */
    198     fread( &tor->downloaded[9], 8, 1, file );
    199     fread( &tor->uploaded[9], 8, 1, file );
     199    if( filesize != sizes[version] )
     200    {
     201        tr_inf( "Wrong size for resume file (%d bytes, %d expected)",
     202                filesize, sizes[version] );
     203        fclose( file );
     204        return 1;
     205    }
     206    fseek( file, 0, SEEK_SET );
     207
     208    if( 1 == version )
     209    {
     210        /* read download and upload totals */
     211        fread( &tor->downloaded[9], 8, 1, file );
     212        fread( &tor->uploaded[9], 8, 1, file );
     213    }
    200214
    201215    /* Compare file mtimes */
Note: See TracChangeset for help on using the changeset viewer.