Skip to content

Commit

Permalink
FIXED: Unable to save resume file: File name too long
Browse files Browse the repository at this point in the history
  • Loading branch information
cfpp2p committed Jul 25, 2017
1 parent 0d84b40 commit 0effab3
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions libtransmission/metainfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,32 @@
****
***/

#define MAX_NAME_LENGTH 219
// 219 + 36 = 255
// . + 16_byte_hash + .torrent + .tmp.XXXXXX = 36 bytes
// . + 16_byte_hash + .resume + .tmp.XXXXXX = 35 bytes
// see tr_bencToFile() for more explanation


char*
tr_metainfoGetBasename( const tr_info * inf )
{
size_t i;
const size_t name_len = strlen( inf->name );
char * ret = tr_strdup_printf( "%s.%16.16s", inf->name, inf->hashString );
char * shortName;

if( !strlen( inf->name ) )
// allow empty name -- substitute
shortName = tr_strdup( "Hash-Name-" );
else if( strlen( inf->name ) <= MAX_NAME_LENGTH )
shortName = tr_strdup( inf->name );
else
// 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 );
tr_free( shortName );

for( i=0; i<name_len; ++i )
if( ( ret[i] == '/' ) || ( ret[i] == '\\' ) )
Expand Down

0 comments on commit 0effab3

Please sign in to comment.