Ignore:
Timestamp:
Nov 10, 2006, 9:30:32 PM (15 years ago)
Author:
titer
Message:

Handle torrents with empty folders (fixes #12)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/inout.c

    r920 r1074  
    251251        }
    252252
     253        /* Empty folders use a dummy "" file, skip those */
     254        if( p == &path[strlen( path ) - 1] )
     255        {
     256            free( path );
     257            continue;
     258        }
     259
    253260        if( stat( path, &sb ) )
    254261        {
     
    434441        }
    435442
    436         /* Now let's get a stream on the file... */
    437         asprintf( &path, "%s/%s", tor->destination, inf->files[i].name );
    438         file = tr_fdFileOpen( tor->fdlimit, path );
    439         if( file < 0 )
    440         {
    441             tr_err( "readOrWriteBytes: could not open file '%s'", path );
     443        if( cur > 0 )
     444        {
     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 );
     448            if( file < 0 )
     449            {
     450                tr_err( "readOrWriteBytes: could not open file '%s'", path );
     451                free( path );
     452                goto fail;
     453            }
    442454            free( path );
    443             goto fail;
    444         }
    445         free( path );
    446 
    447         /* seek to the right offset... */
    448         if( lseek( file, offset, SEEK_SET ) < 0 )
    449         {
    450             goto fail;
    451         }
    452 
    453         /* do what we are here to do... */
    454         if( readOrWrite( file, buf, cur ) != cur )
    455         {
    456             goto fail;
    457         }
    458 
    459         /* and close the stream. */
    460         tr_fdFileRelease( tor->fdlimit, file );
     455
     456            /* seek to the right offset... */
     457            if( lseek( file, offset, SEEK_SET ) < 0 )
     458            {
     459                goto fail;
     460            }
     461
     462            /* do what we are here to do... */
     463            if( readOrWrite( file, buf, cur ) != cur )
     464            {
     465                goto fail;
     466            }
     467
     468            /* and close the stream. */
     469            tr_fdFileRelease( tor->fdlimit, file );
     470        }
    461471
    462472        /* 'cur' bytes done, 'size - cur' bytes to go with the next file */
Note: See TracChangeset for help on using the changeset viewer.