Changeset 12851


Ignore:
Timestamp:
Sep 7, 2011, 4:21:45 AM (10 years ago)
Author:
jordan
Message:

(trunk utils) #4458 "'transmission-edit -a' overwrites the announce field" -- fixed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/utils/edit.c

    r12225 r12851  
    207207
    208208static bool
     209announce_list_has_url( tr_benc * announce_list, const char * url )
     210{
     211    tr_benc * tier;
     212    int tierCount = 0;
     213    while(( tier = tr_bencListChild( announce_list, tierCount++ ))) {
     214        tr_benc * node;
     215        const char * str;
     216        int nodeCount = 0;
     217        while(( node = tr_bencListChild( tier, nodeCount++ )))
     218            if( tr_bencGetStr( node, &str ) && !strcmp( str, url ) )
     219                return true;
     220    }
     221    return false;
     222}
     223
     224static bool
    209225addURL( tr_benc * metainfo, const char * url )
    210226{
    211     const char * str;
    212     tr_benc * announce_list;
     227    const char * announce = NULL;
     228    tr_benc * announce_list = NULL;
    213229    bool changed = false;
    214     bool match = false;
    215 
    216     /* maybe add it to "announce" */
    217     if( !tr_bencDictFindStr( metainfo, "announce", &str ) )
    218     {
     230    const bool had_announce = tr_bencDictFindStr( metainfo, "announce", &announce );
     231    const bool had_announce_list = tr_bencDictFindList( metainfo, "announce-list", &announce_list );
     232
     233    if( !had_announce && !had_announce_list )
     234    {
     235        /* this new tracker is the only one, so add it to "announce"... */
    219236        printf( "\tAdded \"%s\" in \"announce\"\n", url );
    220237        tr_bencDictAddStr( metainfo, "announce", url );
    221238        changed = true;
    222239    }
    223 
    224     /* see if it's already in announce-list */
    225     if( tr_bencDictFindList( metainfo, "announce-list", &announce_list ) ) {
    226         tr_benc * tier;
    227         int tierCount = 0;
    228         while(( tier = tr_bencListChild( announce_list, tierCount++ ))) {
    229             tr_benc * node;
    230             int nodeCount = 0;
    231             while(( node = tr_bencListChild( tier, nodeCount++ )))
    232                 if( tr_bencGetStr( node, &str ) && !strcmp( str, url ) )
    233                     match = true;
    234         }
    235     }
    236 
    237     /* if it's not in announce-list, add it now */
    238     if( !match )
    239     {
    240         tr_benc * tier;
    241 
    242         if( !tr_bencDictFindList( metainfo, "announce-list", &announce_list ) )
    243             announce_list = tr_bencDictAddList( metainfo, "announce-list", 1 );
    244 
    245         tier = tr_bencListAddList( announce_list, 1 );
    246         tr_bencListAddStr( tier, url );
    247         printf( "\tAdded \"%s\" to \"announce-list\" tier %zu\n", url, tr_bencListSize( announce_list ) );
    248         changed = true;
     240    else
     241    {
     242        if( !had_announce_list )
     243        {
     244            announce_list = tr_bencDictAddList( metainfo, "announce-list", 2 );
     245       
     246            if( had_announce )
     247            {
     248                /* we're moving from an 'announce' to an 'announce-list',
     249                 * so copy the old announce URL to the list */
     250                tr_benc * tier = tr_bencListAddList( announce_list, 1 );
     251                tr_bencListAddStr( tier, announce );
     252                changed = true;
     253            }
     254        }
     255
     256        /* If the user-specified URL isn't in the announce list yet, add it */
     257        if( !announce_list_has_url( announce_list, url ) )
     258        {
     259            tr_benc * tier = tr_bencListAddList( announce_list, 1 );
     260            tr_bencListAddStr( tier, url );
     261            printf( "\tAdded \"%s\" to \"announce-list\" tier %zu\n", url, tr_bencListSize( announce_list ) );
     262            changed = true;
     263        }
    249264    }
    250265
Note: See TracChangeset for help on using the changeset viewer.