Changeset 289


Ignore:
Timestamp:
Jun 8, 2006, 4:25:14 AM (17 years ago)
Author:
joshe
Message:

Create any needed parent directories for the
prefs, cache, and torrents directories.

Location:
branches/save_torrent_files/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/save_torrent_files/libtransmission/inout.c

    r261 r289  
    206206
    207207    int           i;
    208     char        * path, * p;
     208    char        * path;
    209209    struct stat   sb;
    210210    int           file;
     
    217217
    218218        /* Create folders */
    219         p = path;
    220         while( ( p = strchr( p, '/' ) ) )
    221         {
    222             *p = '\0';
    223             if( stat( path, &sb ) )
    224             {
    225                 /* Folder doesn't exist yet */
    226                 mkdir( path, 0777 );
    227             }
    228             else if( ( sb.st_mode & S_IFMT ) != S_IFDIR )
    229             {
    230                 /* Node exists but isn't a folder */
    231                 printf( "Remove %s, it's in the way.\n", path );
    232                 free( path );
    233                 return 1;
    234             }
    235             *p = '/';
    236             p++;
     219        if( tr_mkdir( path ) )
     220        {
     221            free( path );
     222            return 1;
    237223        }
    238224
  • branches/save_torrent_files/libtransmission/metainfo.c

    r288 r289  
    115115    if( saveCopy )
    116116    {
    117         /* Create the private torrents directory */
    118         if( mkdir( tr_getTorrentsDirectory(), 0777 ) && EEXIST != errno )
    119         {
    120             fprintf( stderr, "Could not create directory (%s)\n",
    121                      tr_getTorrentsDirectory() );
    122             tr_bencFree( &meta );
    123             free( buf );
    124             return 1;
    125         }
    126 
    127117        /* Save a copy of the torrent file in the private torrent directory */
    128118        snprintf( inf->torrent, MAX_PATH_LENGTH, "%s/%s",
  • branches/save_torrent_files/libtransmission/platform.c

    r288 r289  
    8181#endif
    8282
    83     mkdir( prefsDirectory, 0777 );
     83    tr_mkdir( prefsDirectory );
    8484    init = 1;
    8585
     
    117117#endif
    118118
    119     mkdir( cacheDirectory, 0777 );
     119    tr_mkdir( cacheDirectory );
    120120    init = 1;
    121121
     
    151151#endif
    152152
    153     mkdir( torrentsDirectory, 0777 );
     153    tr_mkdir( torrentsDirectory );
    154154    init = 1;
    155155
  • branches/save_torrent_files/libtransmission/utils.c

    r261 r289  
    9494    return NULL;
    9595}
     96
     97int tr_mkdir( char * path )
     98{
     99    char      * p;
     100    struct stat sb;
     101
     102    p = path;
     103    while( ( p = strchr( p, '/' ) ) )
     104    {
     105        *p = '\0';
     106        if( stat( path, &sb ) )
     107        {
     108            /* Folder doesn't exist yet */
     109            if( mkdir( path, 0777 ) )
     110            {
     111                tr_err( "Could not create directory %s (%s)", path,
     112                        strerror( errno ) );
     113                *p = '/';
     114                return 1;
     115            }
     116        }
     117        else if( ( sb.st_mode & S_IFMT ) != S_IFDIR )
     118        {
     119            /* Node exists but isn't a folder */
     120            tr_err( "Remove %s, it's in the way.", path );
     121            *p = '/';
     122            return 1;
     123        }
     124        *p = '/';
     125        p++;
     126    }
     127
     128    return 0;
     129}
  • branches/save_torrent_files/libtransmission/utils.h

    r261 r289  
    3737
    3838void * tr_memmem( const void *, size_t, const void *, size_t );
     39
     40/***********************************************************************
     41 * tr_mkdir
     42 ***********************************************************************
     43 * Create a directory and any needed parent directories.
     44 * Note that the string passed in must be writable!
     45 **********************************************************************/
     46int tr_mkdir( char * path );
    3947
    4048/***********************************************************************
Note: See TracChangeset for help on using the changeset viewer.