(trunk libT) by request, add a clientData argument to tr_torrentDeleteLocalData()

This commit is contained in:
Charles Kerr 2009-12-09 03:40:35 +00:00
parent c5af8965e0
commit 5f9f97ee2a
4 changed files with 32 additions and 18 deletions

View File

@ -281,10 +281,16 @@ tr_torrent_set_remove_flag( TrTorrent * gtor,
gtor->priv->do_remove = do_remove;
}
static int
deleteFile( const char * filename, void * unused UNUSED )
{
return tr_file_trash_or_remove( filename );
}
void
tr_torrent_delete_files( TrTorrent * gtor )
{
tr_torrentDeleteLocalData( tr_torrent_handle( gtor ), tr_file_trash_or_remove );
tr_torrentDeleteLocalData( tr_torrent_handle( gtor ), deleteFile, NULL );
}
void

View File

@ -239,7 +239,7 @@ torrentRemove( tr_session * session,
const tr_rpc_callback_status status = notify( session, TR_RPC_TORRENT_REMOVING, tor );
tr_bool deleteFlag;
if( tr_bencDictFindBool( args_in, "delete-local-data", &deleteFlag ) && deleteFlag )
tr_torrentDeleteLocalData( tor, NULL );
tr_torrentDeleteLocalData( tor, NULL, NULL );
if( !( status & TR_RPC_NOREMOVE ) )
tr_torrentRemove( tor );
}

View File

@ -2316,15 +2316,15 @@ walkLocalData( const tr_torrent * tor,
}
static void
deleteLocalFile( const char * filename, tr_fileFunc fileFunc )
deleteLocalFile( const char * filename, tr_fileFunc fileFunc, void * fileFuncClientData )
{
struct stat sb;
if( !stat( filename, &sb ) ) /* if file exists... */
fileFunc( filename );
fileFunc( filename, fileFuncClientData );
}
static void
deleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc )
deleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc, void * fileFuncClientData )
{
int i, n;
char ** s;
@ -2352,12 +2352,12 @@ deleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc )
s = (char**) tr_ptrArrayPeek( &folders, &n );
for( i=0; i<n; ++i )
if( tr_ptrArrayFindSorted( &dirtyFolders, s[i], vstrcmp ) == NULL )
deleteLocalFile( s[i], fileFunc );
deleteLocalFile( s[i], fileFunc, fileFuncClientData );
/* now blow away any remaining torrent files, such as torrent files in dirty folders */
for( f=0; f<tor->info.fileCount; ++f ) {
char * path = tr_buildPath( tor->currentDir, tor->info.files[f].name, NULL );
deleteLocalFile( path, fileFunc );
deleteLocalFile( path, fileFunc, fileFuncClientData );
tr_free( path );
}
@ -2374,10 +2374,10 @@ deleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc )
for( i=0; i<n; ++i ) {
#ifdef SYS_DARWIN
char * dsStore = tr_buildPath( s[i], ".DS_Store", NULL );
deleteLocalFile( dsStore, fileFunc );
deleteLocalFile( dsStore, fileFunc, fileFuncClientData );
tr_free( dsStore );
#endif
deleteLocalFile( s[i], fileFunc );
deleteLocalFile( s[i], fileFunc, fileFuncClientData );
}
tr_ptrArrayDestruct( &cleanFolders, NULL );
}
@ -2390,20 +2390,26 @@ deleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc )
tr_free( tmp );
}
static int
removeFile( const char * filename, void * unused UNUSED )
{
return remove( filename );
}
void
tr_torrentDeleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc )
tr_torrentDeleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc, void * fileFuncClientData )
{
assert( tr_isTorrent( tor ) );
if( fileFunc == NULL )
fileFunc = remove;
fileFunc = removeFile;
/* close all the files because we're about to delete them */
tr_fdTorrentClose( tor->session, tor->uniqueId );
if( tor->info.fileCount > 1 )
{
deleteLocalData( tor, fileFunc );
deleteLocalData( tor, fileFunc, fileFuncClientData );
}
else if( tor->info.fileCount == 1 )
{
@ -2411,12 +2417,12 @@ tr_torrentDeleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc )
/* torrent only has one file */
char * path = tr_buildPath( tor->currentDir, tor->info.files[0].name, NULL );
deleteLocalFile( path, fileFunc );
deleteLocalFile( path, fileFunc, fileFuncClientData );
tr_free( path );
tmp = tr_torrentBuildPartial( tor, 0 );
path = tr_buildPath( tor->currentDir, tmp, NULL );
deleteLocalFile( path, fileFunc );
deleteLocalFile( path, fileFunc, fileFuncClientData );
tr_free( path );
tr_free( tmp );
}
@ -2509,7 +2515,7 @@ setLocation( void * vdata )
{
/* blow away the leftover subdirectories in the old location */
if( do_move )
tr_torrentDeleteLocalData( tor, remove );
tr_torrentDeleteLocalData( tor, removeFile, NULL );
/* set the new location and reverify */
tr_torrentSetDownloadDir( tor, location );

View File

@ -1007,8 +1007,6 @@ void tr_torrentStart( tr_torrent * torrent );
/** @brief Stop (pause) a torrent */
void tr_torrentStop( tr_torrent * torrent );
typedef int tr_fileFunc( const char * filename );
enum
{
TR_LOC_MOVING,
@ -1023,6 +1021,8 @@ void tr_torrentSetLocation( tr_torrent * torrent,
double * setme_progress,
int * setme_state );
typedef int tr_fileFunc( const char * filename, void * clientData );
/**
* @brief Deletes the torrent's local data.
* @param torrent
@ -1030,7 +1030,9 @@ void tr_torrentSetLocation( tr_torrent * torrent,
* recycle bins, pass in a function that uses it instead.
* tr_torrentDeleteLocalData() ignores fileFunc's return value.
*/
void tr_torrentDeleteLocalData( tr_torrent * torrent, tr_fileFunc fileFunc );
void tr_torrentDeleteLocalData( tr_torrent * torrent,
tr_fileFunc fileFunc,
void * fileFuncClientData );
uint64_t tr_torrentGetBytesLeftToAllocate( const tr_torrent * torrent );