Ignore:
Timestamp:
Sep 9, 2009, 12:44:11 PM (12 years ago)
Author:
charles
Message:

(trunk, libT) #2390: when you add a new torrent while one is verifying local data, the new torrent will be added on wait list, rather than download automatically. (Reported by Adys in irc)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/verify.c

    r9044 r9082  
    5858    const int64_t buflen = tor->info.pieceSize;
    5959    uint8_t * buffer = tr_new( uint8_t, buflen );
    60 #ifdef STOPWATCH
    6160    const time_t begin = time( NULL );
    62 #endif
     61    time_t end;
    6362
    6463    SHA1_Init( &sha );
     
    160159    tr_free( buffer );
    161160
    162 #ifdef STOPWATCH
    163 {
    164     const time_t end = time( NULL );
    165     fprintf( stderr, "it took %d seconds to verify %"PRIu64" bytes (%"PRIu64" bytes per second)\n",
    166              (int)(end-begin), tor->info.totalSize, (uint64_t)(tor->info.totalSize/(1+(end-begin))) );
    167 }
    168 #endif
     161    /* stopwatch */
     162    end = time( NULL );
     163    tr_tordbg( tor, "it took %d seconds to verify %"PRIu64" bytes (%"PRIu64" bytes per second)",
     164               (int)(end-begin), tor->info.totalSize, (uint64_t)(tor->info.totalSize/(1+(end-begin))) );
    169165
    170166    return changed;
     
    247243}
    248244
     245static tr_bool
     246torrentHasAnyLocalData( const tr_torrent * tor )
     247{
     248    tr_file_index_t i;
     249    tr_bool hasAny = FALSE;
     250    const tr_file_index_t n = tor->info.fileCount;
     251
     252    assert( tr_isTorrent( tor ) );
     253
     254    for( i=0; i<n && !hasAny; ++i )
     255    {
     256        struct stat sb;
     257        char * path = tr_buildPath( tor->downloadDir, tor->info.files[i].name, NULL );
     258        if( !stat( path, &sb ) && ( sb.st_size > 0 ) )
     259            hasAny = TRUE;
     260        tr_free( path );
     261    }
     262
     263    return hasAny;
     264}
     265
    249266void
    250267tr_verifyAdd( tr_torrent *      tor,
    251268              tr_verify_done_cb verify_done_cb )
    252269{
    253     const int uncheckedCount = tr_torrentCountUncheckedPieces( tor );
    254 
    255     assert( tr_isTorrent( tor ) );
    256 
    257     if( !uncheckedCount )
     270    assert( tr_isTorrent( tor ) );
     271
     272    if( tr_torrentCountUncheckedPieces( tor ) == 0 )
    258273    {
    259274        /* doesn't need to be checked... */
     275        fireCheckDone( tor, verify_done_cb );
     276    }
     277    else if( !torrentHasAnyLocalData( tor ) )
     278    {
     279        /* we haven't downloaded anything for this torrent yet...
     280         * no need to leave it waiting in the back of the queue.
     281         * we can mark it as all-missing from here and fire
     282         * the "done" callback */
     283        const tr_bool hadAny = tr_cpHaveTotal( &tor->completion ) != 0;
     284        tr_piece_index_t i;
     285        for( i=0; i<tor->info.pieceCount; ++i )
     286            tr_torrentSetHasPiece( tor, i, FALSE );
     287        if( hadAny ) /* if we thought we had some, flag as dirty */
     288            tr_torrentSetDirty( tor );
    260289        fireCheckDone( tor, verify_done_cb );
    261290    }
Note: See TracChangeset for help on using the changeset viewer.