Ignore:
Timestamp:
Oct 19, 2009, 1:15:46 PM (13 years ago)
Author:
charles
Message:

(trunk libT) make tr_torrentFileCompleted() safe for older torrents that were incomplete before the ".part" feature was added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r9328 r9333  
    25192519tr_torrentFileCompleted( tr_torrent * tor, tr_file_index_t fileNum )
    25202520{
    2521     char * oldpath = tr_torrentFindFile( tor, fileNum );
    2522     char * newpath = tr_strdup( oldpath );
    2523     char * pch = strrchr( newpath, '.' );
    2524     assert( !strcmp( pch, ".part" ) );
    2525     *pch = '\0';
     2521    char * oldpath;
    25262522
    25272523    /* close the file so that we can reopen in read-only mode as needed */
    25282524    tr_fdFileClose( tor, fileNum );
    25292525
    2530     /* strip the trailing ".part" from the filename */
    2531     if( rename( oldpath, newpath ) )
    2532         tr_torerr( tor, "Error moving \"%s\" to \"%s\": %s", oldpath, newpath, tr_strerror( errno ) );
    2533 
    2534     tr_free( newpath );
     2526    /* if the torrent's file ends in ".part" to show that it was incomplete,
     2527     * strip that suffix */
     2528    oldpath = tr_torrentFindFile( tor, fileNum );
     2529    if( oldpath != NULL ) {
     2530        char * newpath = tr_strdup( oldpath );
     2531        char * pch = strrchr( newpath, '.' );
     2532        if(( pch != NULL ) && !strcmp( pch, ".part" )) {
     2533            *pch = '\0';
     2534            if( rename( oldpath, newpath ) )
     2535                tr_torerr( tor, "Error moving \"%s\" to \"%s\": %s", oldpath, newpath, tr_strerror( errno ) );
     2536        }
     2537        tr_free( newpath );
     2538    }
    25352539    tr_free( oldpath );
    25362540}
Note: See TracChangeset for help on using the changeset viewer.