Ignore:
Timestamp:
Jan 18, 2008, 7:13:32 PM (15 years ago)
Author:
charles
Message:

if the torrent's download path doesn't exist, don't create it -- it's might be a removeable disk that got unplugged.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r4598 r4734  
    128128***/
    129129
    130 static int
    131 TrOpenFile( int i, const char * filename, int write )
     130static tr_errno
     131TrOpenFile( int           i,
     132            const char  * folder,
     133            const char  * torrentFile,
     134            int           write )
    132135{
    133136    struct tr_openfile * file = &gFd->open[i];
    134137    int flags;
     138    char filename[MAX_PATH_LENGTH];
     139    struct stat sb;
     140
     141    /* confirm the parent folder exists */
     142    if( stat( folder, &sb ) || !S_ISDIR( sb.st_mode ) )
     143        return TR_ERROR_IO_PARENT;
    135144
    136145    /* create subfolders, if any */
     146    tr_buildPath ( filename, sizeof(filename), folder, torrentFile, NULL );
    137147    if( write ) {
    138148        char * tmp = tr_strdup( filename );
    139         const int val = tr_mkdirp( dirname(tmp), 0777 );
     149        const int err = tr_mkdirp( dirname(tmp), 0777 ) ? errno : 0;
    140150        tr_free( tmp );
    141         if( val )
    142             return tr_ioErrorFromErrno( );
     151        if( err )
     152            return tr_ioErrorFromErrno( err );
    143153    }
    144154
     
    151161    flags |= O_BINARY;
    152162#endif
    153     errno = 0;
    154163    file->fd = open( filename, flags, 0666 );
    155     if( file->fd < 0 ) {
    156         if( errno ) {
    157             tr_err( "Couldn't open '%s': %s", filename, strerror(errno) );
    158             return tr_ioErrorFromErrno();
    159         } else {
    160             tr_err( "Couldn't open '%s'", filename );
    161             return TR_ERROR_IO_OTHER;
    162         }
    163     }
    164 
    165     return TR_OK;
     164    if( file->fd == -1 ) {
     165        const int err = errno;
     166        tr_err( "Couldn't open '%s': %s", filename, strerror(err) );
     167        return tr_ioErrorFromErrno( err );
     168    }
     169
     170    return 0;
    166171}
    167172
     
    193198
    194199int
    195 tr_fdFileCheckout( const char * filename, int write )
     200tr_fdFileCheckout( const char * folder,
     201                   const char * torrentFile,
     202                   int          write )
    196203{
    197204    int i, winner = -1;
    198205    struct tr_openfile * o;
    199 
    200     assert( filename && *filename );
     206    char filename[MAX_PATH_LENGTH];
     207
     208    assert( folder && *folder );
     209    assert( torrentFile && *torrentFile );
    201210    assert( write==0 || write==1 );
    202211
     212    tr_buildPath ( filename, sizeof(filename), folder, torrentFile, NULL );
    203213    dbgmsg( "looking for file '%s', writable %c", filename, write?'y':'n' );
    204214
     
    275285    if( !fileIsOpen( o ) )
    276286    {
    277         const int ret = TrOpenFile( winner, filename, write );
    278         if( ret ) {
     287        const tr_errno err = TrOpenFile( winner, folder, torrentFile, write );
     288        if( err ) {
    279289            tr_lockUnlock( gFd->lock );
    280             return ret;
     290            return err;
    281291        }
    282292
Note: See TracChangeset for help on using the changeset viewer.