Quick & dirty fix to crasher ticket #415.

This commit is contained in:
Charles Kerr 2007-10-26 03:02:23 +00:00
parent 41e9939317
commit e6fbcaeae6
7 changed files with 65 additions and 28 deletions

1
NEWS
View File

@ -11,6 +11,7 @@ NEWS file for Transmission <http://transmission.m0k.org/>
+ Add Dutch localization, re-add Russian localization, fix Korean localization
- gtk:
+ Fix 0.90 packaging errors
+ Fix 0.90 assertion failure: "destination != (void*)0"
0.90 (2007/10/23)
- Encryption support, with option to ignore unencrypted peers

View File

@ -447,7 +447,7 @@ tr_core_load( TrCore * self, gboolean paused )
path = getdownloaddir( );
torrents = tr_loadTorrents ( self->handle, NULL, paused, &count );
torrents = tr_loadTorrents ( self->handle, path, paused, &count );
for( i=0; i<count; ++i )
tr_core_insert( self, tr_torrent_new_preexisting( torrents[i] ) );
tr_free( torrents );

View File

@ -330,11 +330,10 @@ tr_fastResumeSave( const tr_torrent * tor )
}
static int
loadFallbackDestination( tr_torrent * tor, FILE * fp )
loadDestination( tr_torrent * tor, FILE * fp, const char * destination, int argIsFallback )
{
int pathlen = 0;
char path[MAX_PATH_LENGTH];
const int haveDestination = tor->destination && *tor->destination;
for( ;; ) {
const int ch = fgetc( fp );
@ -347,10 +346,10 @@ loadFallbackDestination( tr_torrent * tor, FILE * fp )
path[pathlen] = '\0';
if( pathlen && !haveDestination ) {
tr_free( tor->destination );
tor->destination = tr_strdup( path );
}
if( argIsFallback )
tor->destination = tr_strdup( pathlen ? path : destination );
else
tor->destination = tr_strdup( destination && *destination ? destination : path );
return TR_OK;
}
@ -525,7 +524,9 @@ fastResumeLoadOld( tr_torrent * tor,
static uint64_t
fastResumeLoadImpl ( tr_torrent * tor,
tr_bitfield * uncheckedPieces )
tr_bitfield * uncheckedPieces,
const char * destination,
int argIsFallback )
{
char path[MAX_PATH_LENGTH];
FILE * file;
@ -629,7 +630,7 @@ fastResumeLoadImpl ( tr_torrent * tor,
case FR_ID_DESTINATION:
{
const int rret = loadFallbackDestination( tor, file );
const int rret = loadDestination( tor, file, destination, argIsFallback );
if( rret && ( feof(file) || ferror(file) ) )
{
@ -772,12 +773,17 @@ fastResumeLoadImpl ( tr_torrent * tor,
uint64_t
tr_fastResumeLoad( tr_torrent * tor,
tr_bitfield * uncheckedPieces )
tr_bitfield * uncheckedPieces,
const char * destination,
int argIsFallback )
{
const uint64_t ret = fastResumeLoadImpl( tor, uncheckedPieces );
const uint64_t ret = fastResumeLoadImpl( tor, uncheckedPieces, destination, argIsFallback );
if( ! ( ret & TR_FR_PROGRESS ) )
tr_bitfieldAddRange( uncheckedPieces, 0, tor->info.pieceCount );
if( !tor->destination )
tor->destination = tr_strdup( destination );
return ret;
}

View File

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

View File

@ -257,6 +257,7 @@ static void
torrentRealInit( tr_handle * h,
tr_torrent * tor,
const char * destination,
int destinationIsFallback,
int isPaused )
{
int doStart;
@ -267,8 +268,6 @@ torrentRealInit( tr_handle * h,
tr_globalLock( h );
tor->destination = tr_strdup( destination );
tor->handle = h;
tor->pexDisabled = 0;
@ -339,7 +338,7 @@ torrentRealInit( tr_handle * h,
uncheckedPieces = tr_bitfieldNew( tor->info.pieceCount );
loaded = tr_fastResumeLoad( tor, uncheckedPieces );
loaded = tr_fastResumeLoad( tor, uncheckedPieces, destination, destinationIsFallback );
assert( tor->destination != NULL );
/* the `paused' flag has highest precedence...
@ -449,12 +448,13 @@ tr_torrentParse( const tr_handle * h,
return ret;
}
tr_torrent *
tr_torrentInit( tr_handle * h,
const char * path,
const char * destination,
int isPaused,
int * error )
static tr_torrent *
tr_torrentInitImpl( tr_handle * h,
const char * path,
const char * destination,
int destinationIsFallback,
int isPaused,
int * error )
{
int val;
int tmpError;
@ -469,12 +469,32 @@ tr_torrentInit( tr_handle * h,
*error = TR_EOTHER;
else {
tr_metainfoParseFile( &tor->info, h->tag, path, TRUE );
torrentRealInit( h, tor, destination, isPaused );
torrentRealInit( h, tor, destination, destinationIsFallback, isPaused );
}
return tor;
}
tr_torrent *
tr_torrentInit( tr_handle * h,
const char * path,
const char * destination,
int isPaused,
int * error )
{
return tr_torrentInitImpl( h, path, destination, FALSE, isPaused, error );
}
tr_torrent *
tr_torrentLoad( tr_handle * h,
const char * metainfoFilename,
const char * destination,
int isPaused,
int * error )
{
return tr_torrentInitImpl( h, metainfoFilename, destination, TRUE, isPaused, error );
}
int
tr_torrentParseHash( const tr_handle * h,
const char * hashStr,
@ -520,7 +540,7 @@ tr_torrentInitSaved( tr_handle * h,
*error = TR_EOTHER;
else {
tr_metainfoParseHash( &tor->info, h->tag, hashStr );
torrentRealInit( h, tor, destination, isPaused );
torrentRealInit( h, tor, destination, FALSE, isPaused );
}
return tor;
@ -573,7 +593,7 @@ tr_torrentInitData( tr_handle * h,
*error = TR_EOTHER;
else {
tr_metainfoParseData( &tor->info, h->tag, data, size, TRUE );
torrentRealInit( h, tor, destination, isPaused );
torrentRealInit( h, tor, destination, FALSE, isPaused );
}
return tor;
@ -1303,4 +1323,3 @@ tr_pieceOffset( const tr_torrent * tor, int index, int begin, int length )
ret += length;
return ret;
}

View File

@ -327,7 +327,7 @@ tr_close( tr_handle * h )
tr_torrent **
tr_loadTorrents ( tr_handle * h,
const char * destination,
const char * fallbackDestination,
int isPaused,
int * setmeCount )
{
@ -350,7 +350,7 @@ tr_loadTorrents ( tr_handle * h,
tr_torrent * tor;
char path[MAX_PATH_LENGTH];
tr_buildPath( path, sizeof(path), torrentDir, d->d_name, NULL );
tor = tr_torrentInit( h, path, destination, isPaused, NULL );
tor = tr_torrentLoad( h, path, fallbackDestination, isPaused, NULL );
if( tor != NULL ) {
tr_list_append( &list, tor );
n++;

View File

@ -307,7 +307,7 @@ void tr_close( tr_handle * );
* from the previous session.
*/
tr_torrent ** tr_loadTorrents ( tr_handle * h,
const char * destination,
const char * fallback_destination,
int isPaused,
int * setmeCount );
@ -332,6 +332,15 @@ tr_torrent * tr_torrentInit( tr_handle * handle,
int isPaused,
int * setme_error );
/* This is a stupid hack to fix #415. Probably I should fold all
* these torrent constructors into a single function that takes
* a function object to hold all these esoteric arguments. */
tr_torrent * tr_torrentLoad( tr_handle * handle,
const char * metainfo_filename,
const char * fallback_destination,
int isPaused,
int * setme_error );
typedef struct tr_info tr_info;
/**