static char* getOldTorrentFilename( const tr_session * session, const tr_info * inf ) { int i; char * path; struct stat sb; const int tagCount = 5; const char * tags[] = { "beos", "cli", "daemon", "macosx", "wx" }; /* test the beos, cli, daemon, macosx, wx tags */ for( i=0; i<tagCount; ++i ) { path = tr_strdup_printf( "%s%c%s-%s", tr_getTorrentDir( session ), '/', inf->hashString, tags[i] ); if( !stat( path, &sb ) && ( ( sb.st_mode & S_IFMT ) == S_IFREG ) ) return path; tr_free( path ); } /* test a non-tagged file */ path = tr_buildPath( tr_getTorrentDir( session ), inf->hashString, NULL ); if( !stat( path, &sb ) && ( ( sb.st_mode & S_IFMT ) == S_IFREG ) ) return path; tr_free( path ); /* return the -gtk form by default, since that's the most common case. don't bother testing stat() on it since this is the last candidate and we don't want to return NULL anyway */ return tr_strdup_printf( "%s%c%s-%s", tr_getTorrentDir( session ), '/', inf->hashString, "gtk" ); }
static char* getTorrentFilename(tr_session const* session, tr_info const* inf, enum tr_metainfo_basename_format format) { char* base = tr_metainfoGetBasename(inf, format); char* filename = tr_strdup_printf("%s" TR_PATH_DELIMITER_STR "%s.torrent", tr_getTorrentDir(session), base); tr_free(base); return filename; }
static void metainfoLookupRescan( tr_session * session ) { int i; int n; struct stat sb; const char * dirname = tr_getTorrentDir( session ); DIR * odir = NULL; tr_ctor * ctor = NULL; tr_list * list = NULL; assert( tr_isSession( session ) ); /* walk through the directory and find the mappings */ ctor = tr_ctorNew( session ); tr_ctorSetSave( ctor, FALSE ); /* since we already have them */ if( !stat( dirname, &sb ) && S_ISDIR( sb.st_mode ) && ( ( odir = opendir( dirname ) ) ) ) { struct dirent *d; for( d = readdir( odir ); d != NULL; d = readdir( odir ) ) { if( d->d_name && d->d_name[0] != '.' ) /* skip dotfiles, ., and .. */ { tr_info inf; char * path = tr_buildPath( dirname, d->d_name, NULL ); tr_ctorSetMetainfoFromFile( ctor, path ); if( !tr_torrentParse( session, ctor, &inf ) ) { tr_list_append( &list, tr_strdup( inf.hashString ) ); tr_list_append( &list, tr_strdup( path ) ); tr_metainfoFree( &inf ); } tr_free( path ); } } closedir( odir ); } tr_ctorFree( ctor ); n = tr_list_size( list ) / 2; session->metainfoLookup = tr_new0( struct tr_metainfo_lookup, n ); session->metainfoLookupCount = n; for( i = 0; i < n; ++i ) { char * hashString = tr_list_pop_front( &list ); char * filename = tr_list_pop_front( &list ); memcpy( session->metainfoLookup[i].hashString, hashString, 2 * SHA_DIGEST_LENGTH + 1 ); tr_free( hashString ); session->metainfoLookup[i].filename = filename; } metainfoLookupResort( session ); tr_dbg( "Found %d torrents in \"%s\"", n, dirname ); }
static char* getTorrentFilename (const tr_session * session, const tr_info * inf) { 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* 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 ); }
static char* getOldTorrentFilename( const tr_session * session, const tr_info * inf ) { char * ret; struct evbuffer * buf = tr_getBuffer( ); evbuffer_add_printf( buf, "%s%c%s", tr_getTorrentDir( session ), TR_PATH_DELIMITER, inf->hashString ); if( session->tag ) evbuffer_add_printf( buf, "-%s", session->tag ); ret = tr_strndup( EVBUFFER_DATA( buf ), EVBUFFER_LENGTH( buf ) ); tr_releaseBuffer( buf ); return ret; }
static char* getOldTorrentFilename( const tr_handle * handle, const tr_info * inf ) { char * ret; struct evbuffer * buf = evbuffer_new( ); evbuffer_add_printf( buf, "%s%c%s", tr_getTorrentDir( handle ), TR_PATH_DELIMITER, inf->hashString ); if( handle->tag ) evbuffer_add_printf( buf, "-%s", handle->tag ); ret = tr_strndup( EVBUFFER_DATA( buf ), EVBUFFER_LENGTH( buf ) ); evbuffer_free( buf ); return ret; }
/* this is for really old versions of T and will probably be removed someday */ void tr_metainfoMigrate( tr_session * session, tr_info * inf ) { struct stat new_sb; char * name = getTorrentFilename( session, inf ); if( stat( name, &new_sb ) || ( ( new_sb.st_mode & S_IFMT ) != S_IFREG ) ) { char * old_name = getOldTorrentFilename( session, inf ); size_t contentLen; uint8_t * content; tr_mkdirp( tr_getTorrentDir( session ), 0777 ); if( ( content = tr_loadFile( old_name, &contentLen ) ) ) { FILE * out; errno = 0; out = fopen( name, "wb+" ); if( !out ) { tr_nerr( inf->name, _( "Couldn't create \"%1$s\": %2$s" ), name, tr_strerror( errno ) ); } else { if( fwrite( content, sizeof( uint8_t ), contentLen, out ) == contentLen ) { tr_free( inf->torrent ); inf->torrent = tr_strdup( name ); tr_sessionSetTorrentFile( session, inf->hashString, name ); unlink( old_name ); } fclose( out ); } } tr_free( content ); tr_free( old_name ); } tr_free( name ); }
static void migrateFiles( const tr_handle * handle ) { static int migrated = FALSE; if( !migrated ) { const char * oldDir; const char * newDir; migrated = TRUE; oldDir = getOldTorrentsDir( ); newDir = tr_getTorrentDir( handle ); moveFiles( oldDir, newDir ); oldDir = getOldCacheDir( ); newDir = tr_getResumeDir( handle ); moveFiles( oldDir, newDir ); } }
/** * This function is for transmission-gtk users to migrate the config files * from $HOME/.transmission/ (where they were kept before Transmission 1.30) * to $HOME/.config/$appname as per the XDG directory spec. */ static void migrateFiles( const tr_session * session ) { static int migrated = FALSE; const tr_bool should_migrate = strstr( getOldConfigDir(), ".transmission" ) != NULL; if( !migrated && should_migrate ) { const char * oldDir; const char * newDir; migrated = TRUE; oldDir = getOldTorrentsDir( ); newDir = tr_getTorrentDir( session ); moveFiles( oldDir, newDir ); oldDir = getOldCacheDir( ); newDir = tr_getResumeDir( session ); moveFiles( oldDir, newDir ); } }