Changeset 1646


Ignore:
Timestamp:
Apr 3, 2007, 5:39:41 AM (15 years ago)
Author:
joshe
Message:

Use frontend-specific tags for resume files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fastresume.h

    r1603 r1646  
    3232 * the 5 bytes for the ID and length.
    3333 *
    34  * The name of the resume file is "resume.<hash>".
     34 * The name of the resume file is "resume.<hash>-<tag>", although
     35 * older files with a name of "resume.<hash>" will be recognized if
     36 * the former doesn't exist.
    3537 *
    3638 * All values are stored in the native endianness. Moving a
     
    6466  ( FR_MTIME_LEN( t ) + FR_BLOCK_BITFIELD_LEN( t ) + FR_SLOTPIECE_LEN( t ) )
    6567
    66 static char * fastResumeFileName( tr_io_t * io )
    67 {
    68     char * ret;
    69 
    70     asprintf( &ret, "%s/resume.%s", tr_getCacheDirectory(),
    71               io->tor->info.hashString );
    72 
    73     return ret;
     68static void
     69fastResumeFileName( char * path, size_t size, tr_torrent_t * tor, int tag )
     70{
     71    if( tag )
     72    {
     73        snprintf( path, size, "%s/resume.%s-%s", tr_getCacheDirectory(),
     74                  tor->info.hashString, tor->handle->tag );
     75    }
     76    else
     77    {
     78        snprintf( path, size, "%s/resume.%s", tr_getCacheDirectory(),
     79                  tor->info.hashString );
     80    }
    7481}
    7582
     
    122129{
    123130    tr_torrent_t * tor = io->tor;
    124    
     131
     132    char      path[MAX_PATH_LENGTH];
    125133    FILE    * file;
    126134    int       version = 1;
    127     char    * path;
    128135    uint8_t * buf;
    129136    uint64_t  total;
     
    141148
    142149    /* Create/overwrite the resume file */
    143     path = fastResumeFileName( io );
    144     if( !( file = fopen( path, "w" ) ) )
     150    fastResumeFileName( path, sizeof path, tor, 1 );
     151    file = fopen( path, "w" );
     152    if( NULL == file )
    145153    {
    146154        tr_err( "Could not open '%s' for writing", path );
    147155        free( buf );
    148         free( path );
    149156        return;
    150157    }
     
    185192
    186193    tr_dbg( "Resume file '%s' written", path );
    187     free( path );
    188194}
    189195
     
    293299{
    294300    tr_torrent_t * tor = io->tor;
    295    
     301
     302    char      path[MAX_PATH_LENGTH];
    296303    FILE    * file;
    297304    int       version = 0;
    298     char    * path;
    299305    uint8_t   id;
    300306    uint32_t  len;
     
    302308
    303309    /* Open resume file */
    304     path = fastResumeFileName( io );
    305     if( !( file = fopen( path, "r" ) ) )
    306     {
     310    fastResumeFileName( path, sizeof path, tor, 1 );
     311    file = fopen( path, "r" );
     312    if( NULL == file )
     313    {
     314        if( ENOENT == errno )
     315        {
     316            fastResumeFileName( path, sizeof path, tor, 0 );
     317            file = fopen( path, "r" );
     318            if( NULL != file )
     319            {
     320                goto good;
     321            }
     322            fastResumeFileName( path, sizeof path, tor, 1 );
     323        }
    307324        tr_inf( "Could not open '%s' for reading", path );
    308         free( path );
    309         return 1;
    310     }
     325        return 1;
     326    }
     327  good:
    311328    tr_dbg( "Resume file '%s' loaded", path );
    312     free( path );
    313329
    314330    /* Check format version */
Note: See TracChangeset for help on using the changeset viewer.