Changeset 4734 for trunk/libtransmission/fdlimit.c
- Timestamp:
- Jan 18, 2008, 7:13:32 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/fdlimit.c
r4598 r4734 128 128 ***/ 129 129 130 static int 131 TrOpenFile( int i, const char * filename, int write ) 130 static tr_errno 131 TrOpenFile( int i, 132 const char * folder, 133 const char * torrentFile, 134 int write ) 132 135 { 133 136 struct tr_openfile * file = &gFd->open[i]; 134 137 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; 135 144 136 145 /* create subfolders, if any */ 146 tr_buildPath ( filename, sizeof(filename), folder, torrentFile, NULL ); 137 147 if( write ) { 138 148 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; 140 150 tr_free( tmp ); 141 if( val)142 return tr_ioErrorFromErrno( );151 if( err ) 152 return tr_ioErrorFromErrno( err ); 143 153 } 144 154 … … 151 161 flags |= O_BINARY; 152 162 #endif 153 errno = 0;154 163 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; 166 171 } 167 172 … … 193 198 194 199 int 195 tr_fdFileCheckout( const char * filename, int write ) 200 tr_fdFileCheckout( const char * folder, 201 const char * torrentFile, 202 int write ) 196 203 { 197 204 int i, winner = -1; 198 205 struct tr_openfile * o; 199 200 assert( filename && *filename ); 206 char filename[MAX_PATH_LENGTH]; 207 208 assert( folder && *folder ); 209 assert( torrentFile && *torrentFile ); 201 210 assert( write==0 || write==1 ); 202 211 212 tr_buildPath ( filename, sizeof(filename), folder, torrentFile, NULL ); 203 213 dbgmsg( "looking for file '%s', writable %c", filename, write?'y':'n' ); 204 214 … … 275 285 if( !fileIsOpen( o ) ) 276 286 { 277 const int ret = TrOpenFile( winner, filename, write );278 if( ret) {287 const tr_errno err = TrOpenFile( winner, folder, torrentFile, write ); 288 if( err ) { 279 289 tr_lockUnlock( gFd->lock ); 280 return ret;290 return err; 281 291 } 282 292
Note: See TracChangeset
for help on using the changeset viewer.