Changeset 8464


Ignore:
Timestamp:
May 21, 2009, 6:37:55 PM (12 years ago)
Author:
charles
Message:

(trunk libT) smoke out any errors in the tr_torrentFiles() rewrite

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r8453 r8464  
    667667    tr_metainfoMigrate( session, &tor->info );
    668668
     669{
     670    /* exercise the new tr_torrentFiles() code in the nightly builds...
     671       maybe this will make rolcol stay in-channel */
     672    tr_file_index_t tmpCount;
     673    tr_file_stat * tmp = tr_torrentFiles( tor, &tmpCount );
     674    tr_torrentFilesFree( tmp, tmpCount );
     675}
     676
    669677    if( doStart )
    670678        torrentStart( tor, FALSE );
     
    10371045{
    10381046    uint64_t total = 0;
    1039 
    10401047    const tr_file * f = &tor->info.files[index];
    1041     const tr_block_index_t firstBlock = f->offset / tor->blockSize;
    1042     const uint64_t lastByte = f->offset + f->length - (f->length?1:0);
    1043     const tr_block_index_t lastBlock = lastByte / tor->blockSize;
    1044 
    1045     if( firstBlock == lastBlock )
    1046     {
    1047         if( tr_cpBlockIsCompleteFast( &tor->completion, firstBlock ) )
    1048             total = f->length;
    1049     }
    1050     else
    1051     {
    1052         uint32_t i;
    1053 
    1054         /* the first block */
    1055         if( tr_cpBlockIsCompleteFast( &tor->completion, firstBlock ) )
    1056             total += tor->blockSize - ( f->offset % tor->blockSize );
    1057 
    1058         /* the middle blocks */
    1059         if( f->firstPiece == f->lastPiece )
     1048
     1049    if( f->length )
     1050    {
     1051        const tr_block_index_t firstBlock = f->offset / tor->blockSize;
     1052        const uint64_t lastByte = f->offset + f->length - 1;
     1053        const tr_block_index_t lastBlock = lastByte / tor->blockSize;
     1054
     1055        if( firstBlock == lastBlock )
    10601056        {
    1061             for( i=firstBlock+1; i<lastBlock; ++i )
    1062                 if( tr_cpBlockIsCompleteFast( &tor->completion, i ) )
    1063                     total += tor->blockSize;
     1057            if( tr_cpBlockIsCompleteFast( &tor->completion, firstBlock ) )
     1058                total = f->length;
    10641059        }
    10651060        else
    10661061        {
    1067             int64_t b = 0;
    1068             const tr_block_index_t firstBlockOfLastPiece
    1069                        = tr_torPieceFirstBlock( tor, f->lastPiece );
    1070             const tr_block_index_t lastBlockOfFirstPiece
    1071                        = tr_torPieceFirstBlock( tor, f->firstPiece )
    1072                          + tr_torPieceCountBlocks( tor, f->firstPiece ) - 1;
    1073 
    1074             /* the rest of the first piece */
    1075             for( i=firstBlock+1; i<lastBlock && i<=lastBlockOfFirstPiece; ++i )
    1076                 if( tr_cpBlockIsCompleteFast( &tor->completion, i ) )
    1077                     ++b;
    1078 
    1079             /* the middle pieces */
    1080             if( f->firstPiece + 1 < f->lastPiece )
    1081                 for( i=f->firstPiece+1; i<f->lastPiece; ++i )
    1082                     b += tor->blockCountInPiece - tr_cpMissingBlocksInPiece( &tor->completion, i );
    1083 
    1084             /* the rest of the last piece */
    1085             for( i=firstBlockOfLastPiece; i<lastBlock; ++i )
    1086                 if( tr_cpBlockIsCompleteFast( &tor->completion, i ) )
    1087                     ++b;
    1088 
    1089             b *= tor->blockSize;
    1090             total += b;
     1062            uint32_t i;
     1063
     1064            /* the first block */
     1065            if( tr_cpBlockIsCompleteFast( &tor->completion, firstBlock ) )
     1066                total += tor->blockSize - ( f->offset % tor->blockSize );
     1067
     1068            /* the middle blocks */
     1069            if( f->firstPiece == f->lastPiece )
     1070            {
     1071                for( i=firstBlock+1; i<lastBlock; ++i )
     1072                    if( tr_cpBlockIsCompleteFast( &tor->completion, i ) )
     1073                        total += tor->blockSize;
     1074            }
     1075            else
     1076            {
     1077                int64_t b = 0;
     1078                const tr_block_index_t firstBlockOfLastPiece
     1079                           = tr_torPieceFirstBlock( tor, f->lastPiece );
     1080                const tr_block_index_t lastBlockOfFirstPiece
     1081                           = tr_torPieceFirstBlock( tor, f->firstPiece )
     1082                             + tr_torPieceCountBlocks( tor, f->firstPiece ) - 1;
     1083
     1084                /* the rest of the first piece */
     1085                for( i=firstBlock+1; i<lastBlock && i<=lastBlockOfFirstPiece; ++i )
     1086                    if( tr_cpBlockIsCompleteFast( &tor->completion, i ) )
     1087                        ++b;
     1088
     1089                /* the middle pieces */
     1090                if( f->firstPiece + 1 < f->lastPiece )
     1091                    for( i=f->firstPiece+1; i<f->lastPiece; ++i )
     1092                        b += tor->blockCountInPiece - tr_cpMissingBlocksInPiece( &tor->completion, i );
     1093
     1094                /* the rest of the last piece */
     1095                for( i=firstBlockOfLastPiece; i<lastBlock; ++i )
     1096                    if( tr_cpBlockIsCompleteFast( &tor->completion, i ) )
     1097                        ++b;
     1098
     1099                b *= tor->blockSize;
     1100                total += b;
     1101            }
     1102
     1103            /* the last block */
     1104            if( tr_cpBlockIsCompleteFast( &tor->completion, lastBlock ) )
     1105                total += ( f->offset + f->length ) - ( tor->blockSize * lastBlock );
    10911106        }
    1092 
    1093         /* the last block */
    1094         if( tr_cpBlockIsCompleteFast( &tor->completion, lastBlock ) )
    1095             total += ( lastByte+1 - (lastBlock*tor->blockSize) );
     1107    }
     1108
     1109    if ( total != oldFileBytesCompleted( tor, index ) )
     1110    {
     1111fprintf( stderr, "torrent is [%s], file #%d\n", tor->info.name, (int)index );
     1112fprintf( stderr, "total size  is %"PRIu64"\n", (uint64_t)tor->info.totalSize );
     1113fprintf( stderr, "block size  is %"PRIu64"\n", (uint64_t)tor->blockSize );
     1114fprintf( stderr, "piece size  is %"PRIu64"\n", (uint64_t)tor->info.pieceSize );
     1115fprintf( stderr, "file offset is %"PRIu64"\n", (uint64_t)f->offset );
     1116fprintf( stderr, "file size   is %"PRIu64"\n", (uint64_t)f->length );
     1117fprintf( stderr, " old size   is %"PRIu64"\n", (uint64_t)oldFileBytesCompleted( tor, index ) );
     1118fprintf( stderr, "first piece is %"PRIu64"\n", (uint64_t)f->firstPiece );
     1119fprintf( stderr, "last piece  is %"PRIu64"\n", (uint64_t)f->lastPiece );
     1120fprintf( stderr, " new size   is %"PRIu64"\n", (uint64_t)total );
    10961121    }
    10971122
Note: See TracChangeset for help on using the changeset viewer.