Ignore:
Timestamp:
Jun 18, 2007, 7:39:52 PM (14 years ago)
Author:
charles
Message:
  • fix error checking large files reported by Gimp_
  • portability changes to pathname/filename building
  • small gratuitous changes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/platform.c

    r2034 r2154  
    8282tr_migrateResume( const char *oldDirectory, const char *newDirectory )
    8383{
    84     DIR * dirh;
    85     struct dirent * dirp;
    86     char oldFile[MAX_PATH_LENGTH];
    87     char newFile[MAX_PATH_LENGTH];
    88 
    89     if( ( dirh = opendir( oldDirectory ) ) )
    90     {
     84    DIR * dirh = opendir( oldDirectory );
     85
     86    if( dirh != NULL )
     87    {
     88        struct dirent * dirp;
     89
    9190        while( ( dirp = readdir( dirh ) ) )
    9291        {
    93             if( strncmp( "resume.", dirp->d_name, 7 ) )
    94             {
    95                 continue;
    96             }
    97             snprintf( oldFile, MAX_PATH_LENGTH, "%s/%s",
    98                       oldDirectory, dirp->d_name );
    99             snprintf( newFile, MAX_PATH_LENGTH, "%s/%s",
    100                       newDirectory, dirp->d_name );
    101             rename( oldFile, newFile );
     92            if( !strncmp( "resume.", dirp->d_name, 7 ) )
     93            {
     94                char o[MAX_PATH_LENGTH];
     95                char n[MAX_PATH_LENGTH];
     96                tr_buildPath( o, sizeof(o), oldDirectory, dirp->d_name, NULL );
     97                tr_buildPath( n, sizeof(n), newDirectory, dirp->d_name, NULL );
     98                rename( o, n );
     99            }
    102100        }
    103101
     
    106104}
    107105
    108 char * tr_getPrefsDirectory()
    109 {
    110     static char prefsDirectory[MAX_PATH_LENGTH];
     106const char *
     107tr_getPrefsDirectory( void )
     108{
     109    static char   buf[MAX_PATH_LENGTH];
     110    static int    init = 0;
     111    static size_t buflen = sizeof(buf);
     112    const char* h;
     113
     114    if( init )
     115        return buf;
     116
     117    h = tr_getHomeDirectory();
     118#ifdef SYS_BEOS
     119    find_directory( B_USER_SETTINGS_DIRECTORY,
     120                    dev_for_path("/boot"), true, buf, buflen );
     121    strcat( buf, "/Transmission" );
     122#elif defined( SYS_DARWIN )
     123    tr_buildPath ( buf, buflen, h,
     124                  "Library", "Application Support", "Transmission", NULL );
     125#elif defined(__AMIGAOS4__)
     126    snprintf( buf, buflen, "PROGDIR:.transmission" );
     127#else
     128    tr_buildPath ( buf, buflen, h, ".transmission", NULL );
     129#endif
     130
     131    tr_mkdir( buf );
     132    init = 1;
     133
     134#ifdef SYS_DARWIN
     135    char old[MAX_PATH_LENGTH];
     136    tr_buildPath ( old, sizeof(old), h, ".transmission", NULL );
     137    tr_migrateResume( old, buf );
     138    rmdir( oldDirectory );
     139#endif
     140
     141    return buf;
     142}
     143
     144const char *
     145tr_getCacheDirectory( void )
     146{
     147    static char buf[MAX_PATH_LENGTH];
    111148    static int  init = 0;
     149    static const size_t buflen = sizeof(buf);
     150    const char * p;
    112151
    113152    if( init )
    114     {
    115         return prefsDirectory;
    116     }
    117 
    118 #ifdef SYS_BEOS
    119         find_directory( B_USER_SETTINGS_DIRECTORY, dev_for_path("/boot"),
    120                         true, prefsDirectory, MAX_PATH_LENGTH );
    121         strcat( prefsDirectory, "/Transmission" );
     153        return buf;
     154
     155    p = tr_getPrefsDirectory();
     156#ifdef SYS_BEOS
     157    tr_buildPath( buf, buflen, p, "Cache", NULL );
    122158#elif defined( SYS_DARWIN )
    123     snprintf( prefsDirectory, MAX_PATH_LENGTH,
    124               "%s/Library/Application Support/Transmission",
    125               tr_getHomeDirectory() );
    126 #elif defined(__AMIGAOS4__)
    127     snprintf( prefsDirectory, MAX_PATH_LENGTH, "PROGDIR:.transmission" );
    128 #else
    129     snprintf( prefsDirectory, MAX_PATH_LENGTH, "%s/.transmission",
    130               tr_getHomeDirectory() );
    131 #endif
    132 
    133     tr_mkdir( prefsDirectory );
     159    tr_buildPath( buf, buflen, tr_getHomeDirectory(),
     160                  "Library", "Caches", "Transmission", NULL );
     161#else
     162    tr_buildPath( buf, buflen, p, "cache", NULL );
     163#endif
     164
     165    tr_mkdir( buf );
    134166    init = 1;
    135167
    136 #ifdef SYS_DARWIN
    137     char oldDirectory[MAX_PATH_LENGTH];
    138     snprintf( oldDirectory, MAX_PATH_LENGTH, "%s/.transmission",
    139               tr_getHomeDirectory() );
    140     tr_migrateResume( oldDirectory, prefsDirectory );
    141     rmdir( oldDirectory );
    142 #endif
    143 
    144     return prefsDirectory;
    145 }
    146 
    147 char * tr_getCacheDirectory()
    148 {
    149     static char cacheDirectory[MAX_PATH_LENGTH];
     168    if( strcmp( p, buf ) )
     169        tr_migrateResume( p, buf );
     170
     171    return buf;
     172}
     173
     174const char *
     175tr_getTorrentsDirectory( void )
     176{
     177    static char buf[MAX_PATH_LENGTH];
    150178    static int  init = 0;
     179    static const size_t buflen = sizeof(buf);
     180    const char * p;
    151181
    152182    if( init )
    153     {
    154         return cacheDirectory;
    155     }
    156 
    157 #ifdef SYS_BEOS
    158     /* XXX hey Bryan, is this fine with you? */
    159     snprintf( cacheDirectory, MAX_PATH_LENGTH, "%s/Cache",
    160               tr_getPrefsDirectory() );
     183        return buf;
     184
     185    p = tr_getPrefsDirectory ();
     186
     187#ifdef SYS_BEOS
     188    tr_buildPath( buf, buflen, p, "Torrents", NULL );
    161189#elif defined( SYS_DARWIN )
    162     snprintf( cacheDirectory, MAX_PATH_LENGTH, "%s/Library/Caches/Transmission",
    163               tr_getHomeDirectory() );
    164 #else
    165     snprintf( cacheDirectory, MAX_PATH_LENGTH, "%s/cache",
    166               tr_getPrefsDirectory() );
    167 #endif
    168 
    169     tr_mkdir( cacheDirectory );
     190    tr_buildPath( buf, buflen, p, "Torrents", NULL );
     191#else
     192    tr_buildPath( buf, buflen, p, "torrents", NULL );
     193#endif
     194
     195    tr_mkdir( buf );
    170196    init = 1;
    171 
    172     if( strcmp( tr_getPrefsDirectory(), cacheDirectory ) )
    173     {
    174         tr_migrateResume( tr_getPrefsDirectory(), cacheDirectory );
    175     }
    176 
    177     return cacheDirectory;
    178 }
    179 
    180 char * tr_getTorrentsDirectory()
    181 {
    182     static char torrentsDirectory[MAX_PATH_LENGTH];
    183     static int  init = 0;
    184 
    185     if( init )
    186     {
    187         return torrentsDirectory;
    188     }
    189 
    190 #ifdef SYS_BEOS
    191     /* XXX hey Bryan, is this fine with you? */
    192     snprintf( torrentsDirectory, MAX_PATH_LENGTH, "%s/Torrents",
    193               tr_getPrefsDirectory() );
    194 #elif defined( SYS_DARWIN )
    195     snprintf( torrentsDirectory, MAX_PATH_LENGTH, "%s/Torrents",
    196               tr_getPrefsDirectory() );
    197 #else
    198     snprintf( torrentsDirectory, MAX_PATH_LENGTH, "%s/torrents",
    199               tr_getPrefsDirectory() );
    200 #endif
    201 
    202     tr_mkdir( torrentsDirectory );
    203     init = 1;
    204 
    205     return torrentsDirectory;
     197    return buf;
    206198}
    207199
Note: See TracChangeset for help on using the changeset viewer.