Skip to content

Commit

Permalink
clean utf8 truncated .torrent and .resume file-names (if desired).
Browse files Browse the repository at this point in the history
  • Loading branch information
cfpp2p committed Jul 26, 2017
1 parent 5e660ae commit 5b7532f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
17 changes: 12 additions & 5 deletions libtransmission/metainfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@


char*
tr_metainfoGetBasename( const tr_info * inf )
tr_metainfoGetBasename( const tr_info * inf, const tr_session * session )
{
size_t i;
char * shortName;
char * cleanName;

if( !strlen( inf->name ) )
// allow empty name -- substitute
Expand All @@ -55,11 +56,17 @@ tr_metainfoGetBasename( const tr_info * inf )
// truncate
shortName = tr_strndup( inf->name, MAX_NAME_LENGTH );

char * ret = tr_strdup_printf( "%s.%16.16s", shortName, inf->hashString );

const size_t name_len = strlen( shortName );
if( session && session->cleanUTFenabled )
cleanName = tr_utf8clean( shortName, -1 );
else
cleanName = tr_strdup( shortName );
tr_free( shortName );

char * ret = tr_strdup_printf( "%s.%16.16s", cleanName, inf->hashString );

const size_t name_len = strlen( cleanName );
tr_free( cleanName );

for( i=0; i<name_len; ++i )
if( ret[i] == '/' )
ret[i] = '_';
Expand All @@ -71,7 +78,7 @@ tr_metainfoGetBasename( const tr_info * inf )
static char*
getTorrentFilename( const tr_session * session, const tr_info * inf )
{
char * base = tr_metainfoGetBasename( inf );
char * base = tr_metainfoGetBasename( inf, session );
char * filename = tr_strdup_printf( "%s" TR_PATH_DELIMITER_STR "%s.torrent",
tr_getTorrentDir( session ), base );
tr_free( base );
Expand Down
2 changes: 1 addition & 1 deletion libtransmission/metainfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void tr_metainfoRemoveSaved( const tr_session * session,
void tr_metainfoMigrate( tr_session * session,
tr_info * inf );

char* tr_metainfoGetBasename( const tr_info * );
char* tr_metainfoGetBasename( const tr_info * baseName, const tr_session * session );


#endif
2 changes: 1 addition & 1 deletion libtransmission/resume.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ enum
static char*
getResumeFilename( const tr_torrent * tor )
{
char * base = tr_metainfoGetBasename( tr_torrentInfo( tor ) );
char * base = tr_metainfoGetBasename( tr_torrentInfo( tor ), tor->session );
char * filename = tr_strdup_printf( "%s" TR_PATH_DELIMITER_STR "%s.resume",
tr_getResumeDir( tor->session ), base );
tr_free( base );
Expand Down
2 changes: 1 addition & 1 deletion libtransmission/torrent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ torrentInit( tr_torrent * tor, const tr_ctor * ctor )
if( tr_sessionIsIncompleteDirEnabled( session ) )
tor->incompleteDir = tr_strdup( dir );

s = tr_metainfoGetBasename( &tor->info );
s = tr_metainfoGetBasename( &tor->info, session );
tor->pieceTempDir = tr_buildPath( tr_sessionGetPieceTempDir( tor->session ), s, NULL );
tr_free( s );

Expand Down

0 comments on commit 5b7532f

Please sign in to comment.