Changeset 1201
- Timestamp:
- Dec 13, 2006, 9:41:41 PM (16 years ago)
- Location:
- branches/io/libtransmission
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/io/libtransmission/fdlimit.c
r1200 r1201 203 203 tr_dbg( "Opening %s in %s", name, folder ); 204 204 asprintf( &path, "%s/%s", folder, name ); 205 f->open[winner].file = open( path, write ? O_RDWR : O_RDONLY, 0 );205 f->open[winner].file = open( path, write ? O_RDWR|O_CREAT : O_RDONLY, 0 ); 206 206 free( path ); 207 207 if( f->open[winner].file < 0 ) -
branches/io/libtransmission/inout.c
r1074 r1201 47 47 * Local prototypes 48 48 **********************************************************************/ 49 static int createFiles( tr_io_t * );50 49 static int checkFiles( tr_io_t * ); 51 50 static void closeFiles( tr_io_t * ); … … 96 95 io->tor = tor; 97 96 98 if( c reateFiles( io ) || checkFiles( io ) )97 if( checkFiles( io ) ) 99 98 { 100 99 free( io ); … … 218 217 219 218 /*********************************************************************** 220 * createFiles221 ***********************************************************************222 * Make sure the existing folders/files have correct types and223 * permissions, and create missing folders and files224 **********************************************************************/225 static int createFiles( tr_io_t * io )226 {227 tr_torrent_t * tor = io->tor;228 tr_info_t * inf = &tor->info;229 230 int i;231 char * path, * p;232 struct stat sb;233 int file;234 235 tr_dbg( "Creating files..." );236 237 for( i = 0; i < inf->fileCount; i++ )238 {239 asprintf( &path, "%s/%s", tor->destination, inf->files[i].name );240 241 /* Create folders */242 if( NULL != ( p = strrchr( path, '/' ) ) )243 {244 *p = '\0';245 if( tr_mkdir( path ) )246 {247 free( path );248 return 1;249 }250 *p = '/';251 }252 253 /* Empty folders use a dummy "" file, skip those */254 if( p == &path[strlen( path ) - 1] )255 {256 free( path );257 continue;258 }259 260 if( stat( path, &sb ) )261 {262 /* File doesn't exist yet */263 if( ( file = open( path, O_WRONLY|O_CREAT|O_TRUNC, 0666 ) ) < 0 )264 {265 tr_err( "Could not create `%s' (%s)", path,266 strerror( errno ) );267 free( path );268 return 1;269 }270 close( file );271 }272 else if( ( sb.st_mode & S_IFMT ) != S_IFREG )273 {274 /* Node exists but isn't a file */275 /* XXX this should be reported to the frontend somehow */276 tr_err( "Remove %s, it's in the way.", path );277 free( path );278 return 1;279 }280 281 free( path );282 }283 284 return 0;285 }286 287 /***********************************************************************288 219 * checkFiles 289 220 *********************************************************************** … … 374 305 for( i = 0; i < inf->fileCount; i++ ) 375 306 { 376 asprintf( &path, "%s/%s", tor->destination, inf->files[i].name ); 377 tr_fdFileClose( tor->fdlimit, path ); 378 free( path ); 307 tr_fdFileClose( tor->fdlimit, tor->destination, 308 inf->files[i].name ); 379 309 } 380 310 } … … 443 373 if( cur > 0 ) 444 374 { 445 /* Now let's get a streamon the file... */446 asprintf( &path, "%s/%s", tor->destination, inf->files[i].name );447 file = tr_fdFileOpen( tor->fdlimit, path);375 /* Now let's get a descriptor on the file... */ 376 file = tr_fdFileOpen( tor->fdlimit, tor->destination, 377 inf->files[i].name, isWrite ); 448 378 if( file < 0 ) 449 379 { 450 tr_err( "readOrWriteBytes: could not open file '%s'", path );451 free( path);380 tr_err( "readOrWriteBytes: could not open file '%s'", 381 inf->files[i].name); 452 382 goto fail; 453 383 } 454 free( path );455 384 456 385 /* seek to the right offset... */ … … 466 395 } 467 396 468 /* and close the stream. */397 /* and release the descriptor. */ 469 398 tr_fdFileRelease( tor->fdlimit, file ); 470 399 }
Note: See TracChangeset
for help on using the changeset viewer.