mirror of
https://github.com/transmission/transmission
synced 2025-03-03 10:15:45 +00:00
handle manditory/fallback ctor settings in the bencoded resume filfes
This commit is contained in:
parent
ac921e0f82
commit
2d360434eb
3 changed files with 64 additions and 59 deletions
|
@ -661,61 +661,11 @@ fastResumeLoadImpl ( tr_torrent * tor,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
setFromCtor( tr_torrent * tor, uint64_t fields, const tr_ctor * ctor, int mode )
|
||||
{
|
||||
uint64_t ret = 0;
|
||||
|
||||
if( fields & TR_FR_RUN ) {
|
||||
uint8_t isPaused;
|
||||
if( !tr_ctorGetPaused( ctor, mode, &isPaused ) ) {
|
||||
tor->isRunning = !isPaused;
|
||||
ret |= TR_FR_RUN;
|
||||
}
|
||||
}
|
||||
|
||||
if( fields & TR_FR_MAX_PEERS )
|
||||
if( !tr_ctorGetMaxConnectedPeers( ctor, mode, &tor->maxConnectedPeers ) )
|
||||
ret |= TR_FR_MAX_PEERS;
|
||||
|
||||
if( fields & TR_FR_DESTINATION ) {
|
||||
const char * destination;
|
||||
if( !tr_ctorGetDestination( ctor, mode, &destination ) ) {
|
||||
ret |= TR_FR_DESTINATION;
|
||||
tr_free( tor->destination );
|
||||
tor->destination = tr_strdup( destination );
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
useManditoryFields( tr_torrent * tor, uint64_t fields, const tr_ctor * ctor )
|
||||
{
|
||||
return setFromCtor( tor, fields, ctor, TR_FORCE );
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
useFallbackFields( tr_torrent * tor, uint64_t fields, const tr_ctor * ctor )
|
||||
{
|
||||
return setFromCtor( tor, fields, ctor, TR_FALLBACK );
|
||||
}
|
||||
|
||||
uint64_t
|
||||
tr_fastResumeLoad( tr_torrent * tor,
|
||||
uint64_t fieldsToLoad,
|
||||
const tr_ctor * ctor )
|
||||
uint64_t fieldsToLoad )
|
||||
{
|
||||
uint64_t ret = 0;
|
||||
|
||||
ret |= useManditoryFields( tor, fieldsToLoad, ctor );
|
||||
fieldsToLoad &= ~ret;
|
||||
ret |= fastResumeLoadImpl( tor, fieldsToLoad );
|
||||
fieldsToLoad &= ~ret;
|
||||
ret |= useFallbackFields( tor, fieldsToLoad, ctor );
|
||||
|
||||
return ret;
|
||||
return fastResumeLoadImpl( tor, fieldsToLoad );
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -29,8 +29,7 @@
|
|||
* Returns a bitwise-or'ed set of the data loaded from fastresume
|
||||
*/
|
||||
uint64_t tr_fastResumeLoad( tr_torrent * tor,
|
||||
uint64_t fieldsToLoad,
|
||||
const tr_ctor * ctor );
|
||||
uint64_t fieldsToLoad );
|
||||
|
||||
void tr_fastResumeRemove( const tr_torrent * tor );
|
||||
|
||||
|
|
|
@ -347,7 +347,7 @@ tr_torrentSaveResume( const tr_torrent * tor )
|
|||
tr_benc top;
|
||||
char filename[MAX_PATH_LENGTH];
|
||||
|
||||
tr_bencInitDict( &top, 10 );
|
||||
tr_bencInitDict( &top, 12 );
|
||||
tr_bencDictAddInt( &top, KEY_CORRUPT,
|
||||
tor->corruptPrev + tor->corruptCur );
|
||||
tr_bencDictAddStr( &top, KEY_DESTINATION,
|
||||
|
@ -373,9 +373,8 @@ tr_torrentSaveResume( const tr_torrent * tor )
|
|||
}
|
||||
|
||||
uint64_t
|
||||
tr_torrentLoadResume( tr_torrent * tor,
|
||||
uint64_t fieldsToLoad,
|
||||
const tr_ctor * ctor )
|
||||
loadFromFile( tr_torrent * tor,
|
||||
uint64_t fieldsToLoad )
|
||||
{
|
||||
int64_t i;
|
||||
const char * str;
|
||||
|
@ -388,7 +387,7 @@ tr_torrentLoadResume( tr_torrent * tor,
|
|||
if( tr_bencLoadFile( filename, &top ) )
|
||||
{
|
||||
tr_tordbg( tor, "Couldn't read \"%s\"; trying old format.", filename );
|
||||
fieldsLoaded = tr_fastResumeLoad( tor, fieldsToLoad, ctor );
|
||||
fieldsLoaded = tr_fastResumeLoad( tor, fieldsToLoad );
|
||||
|
||||
if( ( fieldsLoaded != 0 ) && ( fieldsToLoad == ~(uint64_t)0 ) )
|
||||
{
|
||||
|
@ -458,6 +457,63 @@ tr_torrentLoadResume( tr_torrent * tor,
|
|||
return fieldsLoaded;
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
setFromCtor( tr_torrent * tor, uint64_t fields, const tr_ctor * ctor, int mode )
|
||||
{
|
||||
uint64_t ret = 0;
|
||||
|
||||
if( fields & TR_FR_RUN ) {
|
||||
uint8_t isPaused;
|
||||
if( !tr_ctorGetPaused( ctor, mode, &isPaused ) ) {
|
||||
tor->isRunning = !isPaused;
|
||||
ret |= TR_FR_RUN;
|
||||
}
|
||||
}
|
||||
|
||||
if( fields & TR_FR_MAX_PEERS )
|
||||
if( !tr_ctorGetMaxConnectedPeers( ctor, mode, &tor->maxConnectedPeers ) )
|
||||
ret |= TR_FR_MAX_PEERS;
|
||||
|
||||
if( fields & TR_FR_DESTINATION ) {
|
||||
const char * destination;
|
||||
if( !tr_ctorGetDestination( ctor, mode, &destination ) ) {
|
||||
ret |= TR_FR_DESTINATION;
|
||||
tr_free( tor->destination );
|
||||
tor->destination = tr_strdup( destination );
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
useManditoryFields( tr_torrent * tor, uint64_t fields, const tr_ctor * ctor )
|
||||
{
|
||||
return setFromCtor( tor, fields, ctor, TR_FORCE );
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
useFallbackFields( tr_torrent * tor, uint64_t fields, const tr_ctor * ctor )
|
||||
{
|
||||
return setFromCtor( tor, fields, ctor, TR_FALLBACK );
|
||||
}
|
||||
|
||||
uint64_t
|
||||
tr_torrentLoadResume( tr_torrent * tor,
|
||||
uint64_t fieldsToLoad,
|
||||
const tr_ctor * ctor )
|
||||
{
|
||||
uint64_t ret = 0;
|
||||
|
||||
ret |= useManditoryFields( tor, fieldsToLoad, ctor );
|
||||
fieldsToLoad &= ~ret;
|
||||
ret |= loadFromFile( tor, fieldsToLoad );
|
||||
fieldsToLoad &= ~ret;
|
||||
ret |= useFallbackFields( tor, fieldsToLoad, ctor );
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
tr_torrentRemoveResume( const tr_torrent * tor )
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue