From dab899f132870991a0dcf4d26456df85f5ff12f9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 12 Jan 2009 19:58:16 +0000 Subject: [PATCH] (trunk libT) #1427: Files are kept open in read/write mode after a torrent finishes --- libtransmission/torrent.c | 42 +++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 3dbc5eaf0..3e09dc31a 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -20,6 +20,8 @@ #include /* memcmp */ #include /* qsort */ +#include /* evbuffer */ + #include "transmission.h" #include "session.h" #include "bandwidth.h" @@ -1129,23 +1131,33 @@ tr_torrentVerify( tr_torrent * tor ) } static void -stopTorrent( void * vtor ) +tr_torrentCloseLocalFiles( const tr_torrent * tor ) { tr_file_index_t i; + struct evbuffer * buf = evbuffer_new( ); - tr_torrent * tor = vtor; + for( i=0; iinfo.fileCount; ++i ) + { + const tr_file * file = &tor->info.files[i]; + evbuffer_drain( buf, EVBUFFER_LENGTH( buf ) ); + evbuffer_add_printf( buf, "%s%s%s", tor->downloadDir, TR_PATH_DELIMITER_STR, file->name ); + tr_fdFileClose( (const char*) EVBUFFER_DATA( buf ) ); + } + + evbuffer_free( buf ); +} + + +static void +stopTorrent( void * vtor ) +{ + tr_torrent * tor = vtor; tr_verifyRemove( tor ); tr_peerMgrStopTorrent( tor->session->peerMgr, tor->info.hash ); tr_trackerStop( tor->tracker ); - for( i = 0; i < tor->info.fileCount; ++i ) - { - const tr_file * file = &tor->info.files[i]; - char * path = tr_buildPath( tor->downloadDir, file->name, NULL ); - tr_fdFileClose( path ); - tr_free( path ); - } + tr_torrentCloseLocalFiles( tor ); } void @@ -1277,6 +1289,7 @@ tr_torrentRecheckCompleteness( tr_torrent * tor ) } tor->completeness = completeness; + tr_torrentCloseLocalFiles( tor ); fireCompletenessChange( tor, completeness ); if( recentChange && ( completeness == TR_SEED ) ) @@ -1854,13 +1867,6 @@ deleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc ) /* build the set of folders and dirtyFolders */ walkLocalData( tor, root, root, NULL, &torrentFiles, &folders, &dirtyFolders ); - /* close all the files because we're about to delete them */ - for( f=0; finfo.fileCount; ++f ) { - char * path = tr_buildPath( tor->downloadDir, tor->info.files[f].name, NULL ); - tr_fdFileClose( path ); - tr_free( path ); - } - /* try to remove entire folders first, so that the recycle bin will be tidy */ s = (char**) tr_ptrArrayPeek( &folders, &n ); for( i=0; iinfo.fileCount > 1 ) deleteLocalData( tor, fileFunc ); else { /* torrent only has one file */ char * path = tr_buildPath( tor->downloadDir, tor->info.files[0].name, NULL ); - tr_fdFileClose( path ); fileFunc( path ); tr_free( path ); } -- 2.40.0