From bd01906f0c54174ba350cf672733d03f0c0ecd45 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 13 Oct 2007 15:29:15 +0000 Subject: [PATCH] more banging on the fastresume-destination-directory thing. this permuation makes the fastresume destination a fallback, to be used only if the client didn't pass in a directory to tr_torrentInit*() --- libtransmission/fastresume.c | 14 +++++--------- libtransmission/fastresume.h | 1 - libtransmission/torrent.c | 5 +++-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/libtransmission/fastresume.c b/libtransmission/fastresume.c index 9dd5a950a..bfeafb209 100644 --- a/libtransmission/fastresume.c +++ b/libtransmission/fastresume.c @@ -320,10 +320,11 @@ tr_fastResumeSave( const tr_torrent * tor ) } static int -loadDestination( tr_torrent * tor, FILE * fp ) +loadFallbackDestination( tr_torrent * tor, FILE * fp ) { int pathlen = 0; char path[MAX_PATH_LENGTH]; + const int haveDestination = tor->destination && *tor->destination; for( ;; ) { const int ch = fgetc( fp ); @@ -336,7 +337,7 @@ loadDestination( tr_torrent * tor, FILE * fp ) path[pathlen] = '\0'; - if( pathlen ) { + if( pathlen && !haveDestination ) { tr_free( tor->destination ); tor->destination = tr_strdup( path ); } @@ -513,7 +514,6 @@ fastResumeLoadOld( tr_torrent * tor, static uint64_t fastResumeLoadImpl ( tr_torrent * tor, - const char * fallbackDestination, tr_bitfield * uncheckedPieces ) { char path[MAX_PATH_LENGTH]; @@ -526,9 +526,6 @@ fastResumeLoadImpl ( tr_torrent * tor, assert( tor != NULL ); assert( uncheckedPieces != NULL ); - /* initialize the fallback values */ - tor->destination = tr_strdup( fallbackDestination ); - /* Open resume file */ fastResumeFileName( path, sizeof path, tor, 1 ); file = fopen( path, "rb" ); @@ -621,7 +618,7 @@ fastResumeLoadImpl ( tr_torrent * tor, case FR_ID_DESTINATION: { - const int rret = loadDestination( tor, file ); + const int rret = loadFallbackDestination( tor, file ); if( rret && ( feof(file) || ferror(file) ) ) { @@ -751,10 +748,9 @@ fastResumeLoadImpl ( tr_torrent * tor, uint64_t tr_fastResumeLoad( tr_torrent * tor, - const char * fallbackDestination, tr_bitfield * uncheckedPieces ) { - const uint64_t ret = fastResumeLoadImpl( tor, fallbackDestination, uncheckedPieces ); + const uint64_t ret = fastResumeLoadImpl( tor, uncheckedPieces ); if( ! ( ret & TR_FR_PROGRESS ) ) tr_bitfieldAddRange( uncheckedPieces, 0, tor->info.pieceCount ); diff --git a/libtransmission/fastresume.h b/libtransmission/fastresume.h index cc3a777b6..4ee6e897c 100644 --- a/libtransmission/fastresume.h +++ b/libtransmission/fastresume.h @@ -44,7 +44,6 @@ enum * Returns a bitwise-or'ed set of the data loaded from fastresume */ uint64_t tr_fastResumeLoad( tr_torrent * tor, - const char * fallbackDestination, struct tr_bitfield * uncheckedPieces ); #endif diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 8237b7eea..3a452646d 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -269,6 +269,8 @@ torrentRealInit( tr_handle * h, tr_globalLock( h ); + tor->destination = tr_strdup( destination ); + tor->handle = h; tor->pexDisabled = 0; @@ -339,8 +341,7 @@ torrentRealInit( tr_handle * h, uncheckedPieces = tr_bitfieldNew( tor->info.pieceCount ); - loaded = tr_fastResumeLoad( tor, destination, uncheckedPieces ); - + loaded = tr_fastResumeLoad( tor, uncheckedPieces ); assert( tor->destination != NULL ); /* the `paused' flag has highest precedence...