Changeset 1201


Ignore:
Timestamp:
Dec 13, 2006, 9:41:41 PM (15 years ago)
Author:
titer
Message:

Updates inout to work with previous changes

Location:
branches/io/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/io/libtransmission/fdlimit.c

    r1200 r1201  
    203203    tr_dbg( "Opening %s in %s", name, folder );
    204204    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 );
    206206    free( path );
    207207    if( f->open[winner].file < 0 )
  • branches/io/libtransmission/inout.c

    r1074 r1201  
    4747 * Local prototypes
    4848 **********************************************************************/
    49 static int  createFiles( tr_io_t * );
    5049static int  checkFiles( tr_io_t * );
    5150static void closeFiles( tr_io_t * );
     
    9695    io->tor = tor;
    9796
    98     if( createFiles( io ) || checkFiles( io ) )
     97    if( checkFiles( io ) )
    9998    {
    10099        free( io );
     
    218217
    219218/***********************************************************************
    220  * createFiles
    221  ***********************************************************************
    222  * Make sure the existing folders/files have correct types and
    223  * permissions, and create missing folders and files
    224  **********************************************************************/
    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 /***********************************************************************
    288219 * checkFiles
    289220 ***********************************************************************
     
    374305    for( i = 0; i < inf->fileCount; i++ )
    375306    {
    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 );
    379309    }
    380310}
     
    443373        if( cur > 0 )
    444374        {
    445             /* Now let's get a stream on 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 );
    448378            if( file < 0 )
    449379            {
    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);
    452382                goto fail;
    453383            }
    454             free( path );
    455384
    456385            /* seek to the right offset... */
     
    466395            }
    467396
    468             /* and close the stream. */
     397            /* and release the descriptor. */
    469398            tr_fdFileRelease( tor->fdlimit, file );
    470399        }
Note: See TracChangeset for help on using the changeset viewer.