fix another file priority bug.

This commit is contained in:
Charles Kerr 2007-12-25 06:37:21 +00:00
parent f8bc11e094
commit 819b83d90d
4 changed files with 20 additions and 11 deletions

View File

@ -485,7 +485,7 @@ parsePriorities( tr_torrent * tor, const uint8_t * buf, uint32_t len )
case 'h': priority = TR_PRI_HIGH; break;
default: priority = TR_PRI_NORMAL; break;
}
tor->info.files[i].priority = priority;
tr_torrentInitFilePriority( tor, i, priority );
}
/* set the dnd flags */

View File

@ -591,7 +591,7 @@ compareRefillPiece (const void * aIn, const void * bIn)
const struct tr_refill_piece * b = bIn;
/* if one piece has a higher priority, it goes first */
if (a->priority != b->priority)
if( a->priority != b->priority )
return a->priority > b->priority ? -1 : 1;
/* try to fill partial pieces */

View File

@ -213,12 +213,18 @@ initFilePieces ( tr_info * info, int fileIndex )
file->lastPiece = getBytePiece( info, lastByte );
}
static int
pieceHasFile( int piece, const tr_file * file )
{
return ( file->firstPiece <= piece ) && ( piece <= file->lastPiece );
}
static tr_priority_t
calculatePiecePriority ( const tr_torrent * tor,
int piece )
{
int i;
tr_priority_t priority = TR_PRI_LOW;
int priority = TR_PRI_LOW;
/* the piece's priority is the max of the priorities
* of all the files in that piece */
@ -226,10 +232,8 @@ calculatePiecePriority ( const tr_torrent * tor,
{
const tr_file * file = &tor->info.files[i];
if( piece < file->firstPiece )
if( !pieceHasFile( piece, file ) )
continue;
if( piece > file->lastPiece )
break;
priority = MAX( priority, file->priority );
@ -1057,10 +1061,10 @@ tr_torrentIsSeed( const tr_torrent * tor )
*** File priorities
**/
static void
setFilePriority( tr_torrent * tor,
int fileIndex,
tr_priority_t priority )
void
tr_torrentInitFilePriority( tr_torrent * tor,
int fileIndex,
tr_priority_t priority )
{
int i;
tr_file * file;
@ -1089,7 +1093,7 @@ tr_torrentSetFilePriorities( tr_torrent * tor,
tr_torrentLock( tor );
for( i=0; i<fileCount; ++i )
setFilePriority( tor, files[i], priority );
tr_torrentInitFilePriority( tor, files[i], priority );
saveFastResumeNow( tor );
tr_torrentUnlock( tor );

View File

@ -77,6 +77,11 @@ int _tr_block( const tr_torrent * tor, int index, int begin );
uint64_t tr_pieceOffset( const tr_torrent * tor, int index, int begin, int length );
void tr_torrentInitFilePriority( tr_torrent * tor,
int fileIndex,
tr_priority_t priority );
typedef enum
{
TR_RECHECK_NONE,