fix r3379 bug that forced us to recheck the torrents every startup

This commit is contained in:
Charles Kerr 2007-10-13 03:58:54 +00:00
parent 43f03e81ab
commit 05bcd5e01c
3 changed files with 20 additions and 18 deletions

View File

@ -194,6 +194,13 @@ tr_fastResumeSave( const tr_torrent * tor )
/* Write format version */ /* Write format version */
fwrite( &version, 4, 1, file ); fwrite( &version, 4, 1, file );
if( TRUE ) /* FR_ID_DESTINATION */
{
const char * d = tor->destination ? tor->destination : "";
const int byteCount = strlen( d ) + 1;
fastResumeWriteData( FR_ID_DESTINATION, d, 1, byteCount, file );
}
/* Write progress data */ /* Write progress data */
if (1) { if (1) {
int n; int n;
@ -285,13 +292,6 @@ tr_fastResumeSave( const tr_torrent * tor )
fastResumeWriteData( FR_ID_RUN, &is_running, 1, 1, file ); fastResumeWriteData( FR_ID_RUN, &is_running, 1, 1, file );
} }
if( TRUE ) /* FR_ID_DESTINATION */
{
const char * d = tor->destination ? tor->destination : "";
const int byteCount = strlen( d ) + 1;
fastResumeWriteData( FR_ID_DESTINATION, d, 1, byteCount, file );
}
/* Write download and upload totals */ /* Write download and upload totals */
total = tor->downloadedCur + tor->downloadedPrev; total = tor->downloadedCur + tor->downloadedPrev;
@ -513,6 +513,7 @@ fastResumeLoadOld( tr_torrent * tor,
static uint64_t static uint64_t
fastResumeLoadImpl ( tr_torrent * tor, fastResumeLoadImpl ( tr_torrent * tor,
const char * fallbackDestination,
tr_bitfield * uncheckedPieces ) tr_bitfield * uncheckedPieces )
{ {
char path[MAX_PATH_LENGTH]; char path[MAX_PATH_LENGTH];
@ -561,6 +562,7 @@ fastResumeLoadImpl ( tr_torrent * tor,
/* read each block of data */ /* read each block of data */
while( 1 == fread( &id, 1, 1, file ) && 1 == fread( &len, 4, 1, file ) ) while( 1 == fread( &id, 1, 1, file ) && 1 == fread( &len, 4, 1, file ) )
{ {
fprintf( stderr, "reading id %d\n", (int)id );
switch( id ) switch( id )
{ {
case FR_ID_PROGRESS: case FR_ID_PROGRESS:
@ -625,7 +627,10 @@ fastResumeLoadImpl ( tr_torrent * tor,
return ret; return ret;
} }
ret |= TR_FR_DESTINATION;; if( tor->destination == NULL )
tor->destination = tr_strdup( fallbackDestination );
ret |= TR_FR_DESTINATION;
continue; continue;
} }
break; break;
@ -740,6 +745,7 @@ fastResumeLoadImpl ( tr_torrent * tor,
tr_inf( "Skipping resume data type %02x, %u bytes", id, len ); tr_inf( "Skipping resume data type %02x, %u bytes", id, len );
fseek( file, len, SEEK_CUR ); fseek( file, len, SEEK_CUR );
} }
fprintf( stderr, "\n\n" );
fclose( file ); fclose( file );
return ret; return ret;
@ -747,9 +753,10 @@ fastResumeLoadImpl ( tr_torrent * tor,
uint64_t uint64_t
tr_fastResumeLoad( tr_torrent * tor, tr_fastResumeLoad( tr_torrent * tor,
const char * fallbackDestination,
tr_bitfield * uncheckedPieces ) tr_bitfield * uncheckedPieces )
{ {
const uint64_t ret = fastResumeLoadImpl( tor, uncheckedPieces ); const uint64_t ret = fastResumeLoadImpl( tor, fallbackDestination, uncheckedPieces );
if( ! ( ret & TR_FR_PROGRESS ) ) if( ! ( ret & TR_FR_PROGRESS ) )
tr_bitfieldAddRange( uncheckedPieces, 0, tor->info.pieceCount ); tr_bitfieldAddRange( uncheckedPieces, 0, tor->info.pieceCount );

View File

@ -44,6 +44,7 @@ enum
* Returns a bitwise-or'ed set of the data loaded from fastresume * Returns a bitwise-or'ed set of the data loaded from fastresume
*/ */
uint64_t tr_fastResumeLoad( tr_torrent * tor, uint64_t tr_fastResumeLoad( tr_torrent * tor,
const char * fallbackDestination,
struct tr_bitfield * uncheckedPieces ); struct tr_bitfield * uncheckedPieces );
#endif #endif

View File

@ -338,14 +338,8 @@ torrentRealInit( tr_handle * h,
tor->error = TR_OK; tor->error = TR_OK;
uncheckedPieces = tr_bitfieldNew( tor->info.pieceCount ); uncheckedPieces = tr_bitfieldNew( tor->info.pieceCount );
loaded = tr_fastResumeLoad( tor, uncheckedPieces );
/* a path passed in by the user overrides loaded = tr_fastResumeLoad( tor, destination, uncheckedPieces );
the one loaded by fastresume... */
if( destination && *destination ) {
tr_free( tor->destination );
tor->destination = tr_strdup( destination );
}
/* the `paused' flag has highest precedence... /* the `paused' flag has highest precedence...
after that, the fastresume setting is used... after that, the fastresume setting is used...