mirror of
https://github.com/transmission/transmission
synced 2024-12-24 16:52:39 +00:00
#542: handle torrent metainfo files whose info.name tag is missing or empty.
This commit is contained in:
parent
6e1bba6101
commit
ceb608d9a3
1 changed files with 16 additions and 0 deletions
|
@ -10,6 +10,7 @@
|
|||
* $Id:$
|
||||
*/
|
||||
|
||||
#include <libgen.h> /* basename */
|
||||
#include "transmission.h"
|
||||
#include "bencode.h"
|
||||
#include "platform.h"
|
||||
|
@ -84,6 +85,21 @@ tr_ctorSetMetainfoFromFile( tr_ctor * ctor,
|
|||
err = 1;
|
||||
}
|
||||
|
||||
/* if no `name' field was set, then set it from the filename */
|
||||
if( ctor->isSet_metainfo ) {
|
||||
benc_val_t * info = tr_bencDictFindType( &ctor->metainfo, "info", TYPE_DICT );
|
||||
if( info != NULL ) {
|
||||
benc_val_t * name = tr_bencDictFindFirst( info, "name.utf-8", "name", NULL );
|
||||
if( name == NULL )
|
||||
name = tr_bencDictAdd( info, "name" );
|
||||
if( name->type!=TYPE_STR || !name->val.s.s || !*name->val.s.s ) {
|
||||
char * tmp = tr_strdup( filename );
|
||||
tr_bencInitStrDup( name, basename( tmp ) );
|
||||
tr_free( tmp );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tr_free( metainfo );
|
||||
return err;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue