From c5af8965e00bcbbee140ccbb4074cfbb50baa2aa Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 9 Dec 2009 03:00:20 +0000 Subject: [PATCH] (trunk libT) the deleteFunc passed in as the second argument to tr_torrentDeleteLocalData() should /not/ be called unless the file being passed to it actually exists. Reported by livings124 --- libtransmission/torrent.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 640574a53..65f963388 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -2315,6 +2315,14 @@ walkLocalData( const tr_torrent * tor, tr_free( buf ); } +static void +deleteLocalFile( const char * filename, tr_fileFunc fileFunc ) +{ + struct stat sb; + if( !stat( filename, &sb ) ) /* if file exists... */ + fileFunc( filename ); +} + static void deleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc ) { @@ -2344,12 +2352,12 @@ deleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc ) s = (char**) tr_ptrArrayPeek( &folders, &n ); for( i=0; iinfo.fileCount; ++f ) { char * path = tr_buildPath( tor->currentDir, tor->info.files[f].name, NULL ); - fileFunc( path ); + deleteLocalFile( path, fileFunc ); tr_free( path ); } @@ -2366,10 +2374,10 @@ deleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc ) for( i=0; icurrentDir, tor->info.files[0].name, NULL ); - fileFunc( path ); + deleteLocalFile( path, fileFunc ); tr_free( path ); tmp = tr_torrentBuildPartial( tor, 0 ); path = tr_buildPath( tor->currentDir, tmp, NULL ); - fileFunc( path ); + deleteLocalFile( path, fileFunc ); tr_free( path ); tr_free( tmp ); }