Changeset 4437


Ignore:
Timestamp:
Jan 3, 2008, 4:01:29 PM (14 years ago)
Author:
charles
Message:

#542: handle torrent metainfo files whose info.name tag is missing or empty.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent-ctor.c

    r4404 r4437  
    1111 */
    1212
     13#include <libgen.h> /* basename */
    1314#include "transmission.h"
    1415#include "bencode.h"
     
    8384        clearMetainfo( ctor );
    8485        err = 1;
     86    }
     87
     88    /* if no `name' field was set, then set it from the filename */
     89    if( ctor->isSet_metainfo ) {
     90        benc_val_t * info = tr_bencDictFindType( &ctor->metainfo, "info", TYPE_DICT );
     91        if( info != NULL ) {
     92            benc_val_t * name = tr_bencDictFindFirst( info, "name.utf-8", "name", NULL );
     93            if( name == NULL )
     94                name = tr_bencDictAdd( info, "name" );
     95            if( name->type!=TYPE_STR || !name->val.s.s || !*name->val.s.s ) {
     96                char * tmp = tr_strdup( filename );
     97                tr_bencInitStrDup( name, basename( tmp ) );
     98                tr_free( tmp );
     99            }
     100        }
    85101    }
    86102
Note: See TracChangeset for help on using the changeset viewer.