From 36824664885dcf46e20610119083a5d335bbd61a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 20 Apr 2010 23:14:00 +0000 Subject: [PATCH] (trunk libT) #3136 "slashes in magnet names" -- fixed in trunk for 2.00 --- libtransmission/metainfo.c | 26 +++++++++++++++++++++----- libtransmission/metainfo.h | 2 ++ libtransmission/resume.c | 13 +++++++------ libtransmission/torrent-magnet.c | 4 ++-- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/libtransmission/metainfo.c b/libtransmission/metainfo.c index 3dc9aea78..d44df6363 100644 --- a/libtransmission/metainfo.c +++ b/libtransmission/metainfo.c @@ -34,15 +34,31 @@ **** ***/ +char* +tr_metainfoGetBasename( const tr_info * inf ) +{ + char *ret, *pch, *name; + + name = tr_strdup( inf->name ); + for( pch=name; pch && *pch; ++pch ) + if( *pch == '/' ) + *pch = '_'; + + ret = tr_strdup_printf( "%s.%16.16s", name, inf->hashString ); + + tr_free( name ); + return ret; +} + static char* getTorrentFilename( const tr_session * session, const tr_info * inf ) { - return tr_strdup_printf( "%s%c%s.%16.16s.torrent", - tr_getTorrentDir( session ), - TR_PATH_DELIMITER, - inf->name, - inf->hashString ); + char * base = tr_metainfoGetBasename( inf ); + char * filename = tr_strdup_printf( "%s" TR_PATH_DELIMITER_STR "%s.torrent", + tr_getTorrentDir( session ), base ); + tr_free( base ); + return filename; } static char* diff --git a/libtransmission/metainfo.h b/libtransmission/metainfo.h index f9273f131..116de21de 100644 --- a/libtransmission/metainfo.h +++ b/libtransmission/metainfo.h @@ -34,5 +34,7 @@ void tr_metainfoRemoveSaved( const tr_session * session, void tr_metainfoMigrate( tr_session * session, tr_info * inf ); +char* tr_metainfoGetBasename( const tr_info * ); + #endif diff --git a/libtransmission/resume.c b/libtransmission/resume.c index 173b9be7e..7cf879665 100644 --- a/libtransmission/resume.c +++ b/libtransmission/resume.c @@ -17,8 +17,9 @@ #include "transmission.h" #include "bencode.h" #include "completion.h" +#include "metainfo.h" /* tr_metainfoGetBasename() */ #include "peer-mgr.h" /* pex */ -#include "platform.h" /* tr_getResumeDir */ +#include "platform.h" /* tr_getResumeDir() */ #include "resume.h" #include "session.h" #include "torrent.h" @@ -67,11 +68,11 @@ enum static char* getResumeFilename( const tr_torrent * tor ) { - return tr_strdup_printf( "%s%c%s.%16.16s.resume", - tr_getResumeDir( tor->session ), - TR_PATH_DELIMITER, - tr_torrentName( tor ), - tor->info.hashString ); + char * base = tr_metainfoGetBasename( tr_torrentInfo( tor ) ); + char * filename = tr_strdup_printf( "%s" TR_PATH_DELIMITER_STR "%s.resume", + tr_getResumeDir( tor->session ), base ); + tr_free( base ); + return filename; } /*** diff --git a/libtransmission/torrent-magnet.c b/libtransmission/torrent-magnet.c index 236451722..a21550fa3 100644 --- a/libtransmission/torrent-magnet.c +++ b/libtransmission/torrent-magnet.c @@ -75,8 +75,8 @@ tr_torrentSetMetadataSizeHint( tr_torrent * tor, int size ) { int i; struct tr_incomplete_metadata * m; - int n = ( size + ( METADATA_PIECE_SIZE - 1 ) ) / METADATA_PIECE_SIZE; - dbgmsg( tor, "there are %d pieces", n ); + const int n = ( size + ( METADATA_PIECE_SIZE - 1 ) ) / METADATA_PIECE_SIZE; + dbgmsg( tor, "metadata is %d bytes in %d pieces", size, n ); m = tr_new( struct tr_incomplete_metadata, 1 ); m->pieceCount = n;