Ignore:
Timestamp:
Nov 21, 2007, 4:16:59 PM (14 years ago)
Author:
charles
Message:

fix ticket #451 (Files remain in use after removal)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r3883 r3918  
    9898    unsigned int  isCheckedOut : 1;
    9999    unsigned int  isWritable : 1;
     100    unsigned int  closeWhenDone : 1;
    100101    char          filename[MAX_PATH_LENGTH];
    101102    int           fd;
     
    190191
    191192int
    192 tr_fdFileOpen( const char * filename, int write )
     193tr_fdFileCheckout( const char * filename, int write )
    193194{
    194195    int i, winner;
     
    283284    dbgmsg( "checking out '%s' in slot %d", filename, winner );
    284285    o->isCheckedOut = 1;
     286    o->closeWhenDone = 0;
    285287    o->date = tr_date( );
    286288    tr_lockUnlock( gFd->lock );
     
    289291
    290292void
    291 tr_fdFileRelease( int file )
     293tr_fdFileReturn( int fd )
    292294{
    293295    int i;
    294296    tr_lockLock( gFd->lock );
    295297
    296     for( i=0; i<TR_MAX_OPEN_FILES; ++i ) {
     298    for( i=0; i<TR_MAX_OPEN_FILES; ++i )
     299    {
    297300        struct tr_openfile * o = &gFd->open[i];
    298         if( o->fd == file ) {
    299             dbgmsg( "releasing file '%s' in slot #%d", o->filename, i );
    300             /* fsync( o->fd ); */
    301             o->isCheckedOut = 0;
    302             break;
     301        if( o->fd != fd )
     302            continue;
     303
     304        dbgmsg( "releasing file '%s' in slot #%d", o->filename, i );
     305        o->isCheckedOut = 0;
     306        if( o->closeWhenDone )
     307            TrCloseFile( i );
     308       
     309        break;
     310    }
     311   
     312    tr_condSignal( gFd->cond );
     313    tr_lockUnlock( gFd->lock );
     314}
     315
     316void
     317tr_fdFileClose( const char * filename )
     318{
     319    int i;
     320    tr_lockLock( gFd->lock );
     321    dbgmsg( "tr_fdFileClose closing '%s'", filename );
     322
     323    for( i=0; i<TR_MAX_OPEN_FILES; ++i )
     324    {
     325        struct tr_openfile * o = &gFd->open[i];
     326        if( !fileIsOpen(o) || strcmp(filename,o->filename) )
     327            continue;
     328
     329        if( !o->isCheckedOut ) {
     330            dbgmsg( "not checked out, so closing it now... '%s'", filename );
     331            TrCloseFile( i );
     332        } else {
     333            dbgmsg( "flagging file '%s', slot #%d to be closed when checked in", gFd->open[i].filename, i );
     334            o->closeWhenDone = 1;
    303335        }
    304336    }
Note: See TracChangeset for help on using the changeset viewer.