Changeset 5641


Ignore:
Timestamp:
Apr 18, 2008, 12:47:13 PM (14 years ago)
Author:
charles
Message:

handle manditory/fallback ctor settings in the bencoded resume filfes

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fastresume.c

    r5616 r5641  
    662662}
    663663
    664 static uint64_t
    665 setFromCtor( tr_torrent * tor, uint64_t fields, const tr_ctor * ctor, int mode )
    666 {
    667     uint64_t ret = 0;
    668 
    669     if( fields & TR_FR_RUN ) {
    670         uint8_t isPaused;
    671         if( !tr_ctorGetPaused( ctor, mode, &isPaused ) ) {
    672             tor->isRunning = !isPaused;
    673             ret |= TR_FR_RUN;
    674         }
    675     }
    676 
    677     if( fields & TR_FR_MAX_PEERS )
    678         if( !tr_ctorGetMaxConnectedPeers( ctor, mode, &tor->maxConnectedPeers ) )
    679             ret |= TR_FR_MAX_PEERS;
    680 
    681     if( fields & TR_FR_DESTINATION ) {
    682         const char * destination;
    683         if( !tr_ctorGetDestination( ctor, mode, &destination ) ) {
    684             ret |= TR_FR_DESTINATION;
    685             tr_free( tor->destination );
    686             tor->destination = tr_strdup( destination );
    687         }
    688     }
    689 
    690     return ret;
    691 }
    692 
    693 static uint64_t
    694 useManditoryFields( tr_torrent * tor, uint64_t fields, const tr_ctor * ctor )
    695 {
    696     return setFromCtor( tor, fields, ctor, TR_FORCE );
    697 }
    698 
    699 static uint64_t
    700 useFallbackFields( tr_torrent * tor, uint64_t fields, const tr_ctor * ctor )
    701 {
    702     return setFromCtor( tor, fields, ctor, TR_FALLBACK );
    703 }
    704 
    705664uint64_t
    706665tr_fastResumeLoad( tr_torrent     * tor,
    707                    uint64_t         fieldsToLoad,
    708                    const tr_ctor  * ctor )
    709 {
    710     uint64_t ret = 0;
    711 
    712     ret |= useManditoryFields( tor, fieldsToLoad, ctor );
    713     fieldsToLoad &= ~ret;
    714     ret |= fastResumeLoadImpl( tor, fieldsToLoad );
    715     fieldsToLoad &= ~ret;
    716     ret |= useFallbackFields( tor, fieldsToLoad, ctor );
    717 
    718     return ret;
     666                   uint64_t         fieldsToLoad )
     667{
     668    return fastResumeLoadImpl( tor, fieldsToLoad );
    719669}
    720670
  • trunk/libtransmission/fastresume.h

    r5616 r5641  
    3030 */
    3131uint64_t tr_fastResumeLoad( tr_torrent          * tor,
    32                             uint64_t              fieldsToLoad,
    33                             const tr_ctor       * ctor );
     32                            uint64_t              fieldsToLoad );
    3433
    3534void tr_fastResumeRemove( const tr_torrent * tor );
  • trunk/libtransmission/resume.c

    r5627 r5641  
    348348    char filename[MAX_PATH_LENGTH];
    349349
    350     tr_bencInitDict( &top, 10 );
     350    tr_bencInitDict( &top, 12 );
    351351    tr_bencDictAddInt( &top, KEY_CORRUPT,
    352352                             tor->corruptPrev + tor->corruptCur );
     
    374374
    375375uint64_t
    376 tr_torrentLoadResume( tr_torrent    * tor,
    377                       uint64_t        fieldsToLoad,
    378                       const tr_ctor * ctor )
     376loadFromFile( tr_torrent    * tor,
     377              uint64_t        fieldsToLoad )
    379378{
    380379    int64_t i;
     
    389388    {
    390389        tr_tordbg( tor, "Couldn't read \"%s\"; trying old format.", filename );
    391         fieldsLoaded = tr_fastResumeLoad( tor, fieldsToLoad, ctor );
     390        fieldsLoaded = tr_fastResumeLoad( tor, fieldsToLoad );
    392391
    393392        if( ( fieldsLoaded != 0 ) && ( fieldsToLoad == ~(uint64_t)0 ) )
     
    459458}
    460459
     460static uint64_t
     461setFromCtor( tr_torrent * tor, uint64_t fields, const tr_ctor * ctor, int mode )
     462{
     463    uint64_t ret = 0;
     464
     465    if( fields & TR_FR_RUN ) {
     466        uint8_t isPaused;
     467        if( !tr_ctorGetPaused( ctor, mode, &isPaused ) ) {
     468            tor->isRunning = !isPaused;
     469            ret |= TR_FR_RUN;
     470        }
     471    }
     472
     473    if( fields & TR_FR_MAX_PEERS )
     474        if( !tr_ctorGetMaxConnectedPeers( ctor, mode, &tor->maxConnectedPeers ) )
     475            ret |= TR_FR_MAX_PEERS;
     476
     477    if( fields & TR_FR_DESTINATION ) {
     478        const char * destination;
     479        if( !tr_ctorGetDestination( ctor, mode, &destination ) ) {
     480            ret |= TR_FR_DESTINATION;
     481            tr_free( tor->destination );
     482            tor->destination = tr_strdup( destination );
     483        }
     484    }
     485
     486    return ret;
     487}
     488
     489static uint64_t
     490useManditoryFields( tr_torrent * tor, uint64_t fields, const tr_ctor * ctor )
     491{
     492    return setFromCtor( tor, fields, ctor, TR_FORCE );
     493}
     494
     495static uint64_t
     496useFallbackFields( tr_torrent * tor, uint64_t fields, const tr_ctor * ctor )
     497{
     498    return setFromCtor( tor, fields, ctor, TR_FALLBACK );
     499}
     500
     501uint64_t
     502tr_torrentLoadResume( tr_torrent    * tor,
     503                      uint64_t        fieldsToLoad,
     504                      const tr_ctor * ctor )
     505{
     506    uint64_t ret = 0;
     507
     508    ret |= useManditoryFields( tor, fieldsToLoad, ctor );
     509    fieldsToLoad &= ~ret;
     510    ret |= loadFromFile( tor, fieldsToLoad );
     511    fieldsToLoad &= ~ret;
     512    ret |= useFallbackFields( tor, fieldsToLoad, ctor );
     513
     514    return ret;
     515}
     516
    461517void
    462518tr_torrentRemoveResume( const tr_torrent * tor )
Note: See TracChangeset for help on using the changeset viewer.