mirror of
https://github.com/transmission/transmission
synced 2025-03-11 14:43:42 +00:00
(trunk utils) #4458 "'transmission-edit -a' overwrites the announce field" -- fixed.
This commit is contained in:
parent
cca9af71ef
commit
8424c35ab3
1 changed files with 44 additions and 29 deletions
63
utils/edit.c
63
utils/edit.c
|
@ -206,47 +206,62 @@ replaceURL( tr_benc * metainfo, const char * in, const char * out )
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
addURL( tr_benc * metainfo, const char * url )
|
announce_list_has_url( tr_benc * announce_list, const char * url )
|
||||||
{
|
{
|
||||||
const char * str;
|
|
||||||
tr_benc * announce_list;
|
|
||||||
bool changed = false;
|
|
||||||
bool match = false;
|
|
||||||
|
|
||||||
/* maybe add it to "announce" */
|
|
||||||
if( !tr_bencDictFindStr( metainfo, "announce", &str ) )
|
|
||||||
{
|
|
||||||
printf( "\tAdded \"%s\" in \"announce\"\n", url );
|
|
||||||
tr_bencDictAddStr( metainfo, "announce", url );
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* see if it's already in announce-list */
|
|
||||||
if( tr_bencDictFindList( metainfo, "announce-list", &announce_list ) ) {
|
|
||||||
tr_benc * tier;
|
tr_benc * tier;
|
||||||
int tierCount = 0;
|
int tierCount = 0;
|
||||||
while(( tier = tr_bencListChild( announce_list, tierCount++ ))) {
|
while(( tier = tr_bencListChild( announce_list, tierCount++ ))) {
|
||||||
tr_benc * node;
|
tr_benc * node;
|
||||||
|
const char * str;
|
||||||
int nodeCount = 0;
|
int nodeCount = 0;
|
||||||
while(( node = tr_bencListChild( tier, nodeCount++ )))
|
while(( node = tr_bencListChild( tier, nodeCount++ )))
|
||||||
if( tr_bencGetStr( node, &str ) && !strcmp( str, url ) )
|
if( tr_bencGetStr( node, &str ) && !strcmp( str, url ) )
|
||||||
match = true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* if it's not in announce-list, add it now */
|
static bool
|
||||||
if( !match )
|
addURL( tr_benc * metainfo, const char * url )
|
||||||
|
{
|
||||||
|
const char * announce = NULL;
|
||||||
|
tr_benc * announce_list = NULL;
|
||||||
|
bool changed = false;
|
||||||
|
const bool had_announce = tr_bencDictFindStr( metainfo, "announce", &announce );
|
||||||
|
const bool had_announce_list = tr_bencDictFindList( metainfo, "announce-list", &announce_list );
|
||||||
|
|
||||||
|
if( !had_announce && !had_announce_list )
|
||||||
{
|
{
|
||||||
tr_benc * tier;
|
/* this new tracker is the only one, so add it to "announce"... */
|
||||||
|
printf( "\tAdded \"%s\" in \"announce\"\n", url );
|
||||||
|
tr_bencDictAddStr( metainfo, "announce", url );
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( !had_announce_list )
|
||||||
|
{
|
||||||
|
announce_list = tr_bencDictAddList( metainfo, "announce-list", 2 );
|
||||||
|
|
||||||
if( !tr_bencDictFindList( metainfo, "announce-list", &announce_list ) )
|
if( had_announce )
|
||||||
announce_list = tr_bencDictAddList( metainfo, "announce-list", 1 );
|
{
|
||||||
|
/* we're moving from an 'announce' to an 'announce-list',
|
||||||
|
* so copy the old announce URL to the list */
|
||||||
|
tr_benc * tier = tr_bencListAddList( announce_list, 1 );
|
||||||
|
tr_bencListAddStr( tier, announce );
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tier = tr_bencListAddList( announce_list, 1 );
|
/* If the user-specified URL isn't in the announce list yet, add it */
|
||||||
|
if( !announce_list_has_url( announce_list, url ) )
|
||||||
|
{
|
||||||
|
tr_benc * tier = tr_bencListAddList( announce_list, 1 );
|
||||||
tr_bencListAddStr( tier, url );
|
tr_bencListAddStr( tier, url );
|
||||||
printf( "\tAdded \"%s\" to \"announce-list\" tier %zu\n", url, tr_bencListSize( announce_list ) );
|
printf( "\tAdded \"%s\" to \"announce-list\" tier %zu\n", url, tr_bencListSize( announce_list ) );
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue