Changeset 7687


Ignore:
Timestamp:
Jan 12, 2009, 7:58:16 PM (12 years ago)
Author:
charles
Message:

(trunk libT) #1427: Files are kept open in read/write mode after a torrent finishes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r7663 r7687  
    2020#include <string.h> /* memcmp */
    2121#include <stdlib.h> /* qsort */
     22
     23#include <event.h> /* evbuffer */
    2224
    2325#include "transmission.h"
     
    11301132
    11311133static void
     1134tr_torrentCloseLocalFiles( const tr_torrent * tor )
     1135{
     1136    tr_file_index_t i;
     1137    struct evbuffer * buf = evbuffer_new( );
     1138
     1139    for( i=0; i<tor->info.fileCount; ++i )
     1140    {
     1141        const tr_file * file = &tor->info.files[i];
     1142        evbuffer_drain( buf, EVBUFFER_LENGTH( buf ) );
     1143        evbuffer_add_printf( buf, "%s%s%s", tor->downloadDir, TR_PATH_DELIMITER_STR, file->name );
     1144        tr_fdFileClose( (const char*) EVBUFFER_DATA( buf ) );
     1145    }
     1146
     1147    evbuffer_free( buf );
     1148}
     1149
     1150
     1151static void
    11321152stopTorrent( void * vtor )
    11331153{
    1134     tr_file_index_t i;
    1135 
    1136     tr_torrent *    tor = vtor;
     1154    tr_torrent * tor = vtor;
    11371155
    11381156    tr_verifyRemove( tor );
     
    11401158    tr_trackerStop( tor->tracker );
    11411159
    1142     for( i = 0; i < tor->info.fileCount; ++i )
    1143     {
    1144         const tr_file * file = &tor->info.files[i];
    1145         char * path = tr_buildPath( tor->downloadDir, file->name, NULL );
    1146         tr_fdFileClose( path );
    1147         tr_free( path );
    1148     }
     1160    tr_torrentCloseLocalFiles( tor );
    11491161}
    11501162
     
    12781290
    12791291        tor->completeness = completeness;
     1292        tr_torrentCloseLocalFiles( tor );
    12801293        fireCompletenessChange( tor, completeness );
    12811294
     
    18551868    walkLocalData( tor, root, root, NULL, &torrentFiles, &folders, &dirtyFolders );
    18561869
    1857     /* close all the files because we're about to delete them */
    1858     for( f=0; f<tor->info.fileCount; ++f ) {
    1859         char * path = tr_buildPath( tor->downloadDir, tor->info.files[f].name, NULL );
    1860         tr_fdFileClose( path );
    1861         tr_free( path );
    1862     }
    1863 
    18641870    /* try to remove entire folders first, so that the recycle bin will be tidy */
    18651871    s = (char**) tr_ptrArrayPeek( &folders, &n );
     
    19041910        fileFunc = unlink;
    19051911
     1912    /* close all the files because we're about to delete them */
     1913    tr_torrentCloseLocalFiles( tor );
     1914
    19061915    if( tor->info.fileCount > 1 )
    19071916        deleteLocalData( tor, fileFunc );
     
    19091918        /* torrent only has one file */
    19101919        char * path = tr_buildPath( tor->downloadDir, tor->info.files[0].name, NULL );
    1911         tr_fdFileClose( path );
    19121920        fileFunc( path );
    19131921        tr_free( path );
Note: See TracChangeset for help on using the changeset viewer.