From a33b78fc5317fdbacf97efa4b3a99270eb38cf9c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 9 Dec 2008 17:01:49 +0000 Subject: [PATCH] (daemon) #1510: kysucix's patch to give an option to delete local data via RPC when removing a torrent. --- daemon/remote.c | 8 ++++++++ daemon/transmission-remote.1 | 4 ++++ doc/rpc-spec.txt | 14 +++++++++++++- libtransmission/rpcimpl.c | 19 +++++++++++-------- libtransmission/torrent.c | 15 +++++++++++++++ libtransmission/tr-getopt.c | 5 +++-- libtransmission/transmission.h | 3 +++ 7 files changed, 57 insertions(+), 11 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index 0e8507ec8..2c5c537d4 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -99,6 +99,8 @@ static tr_option opts[] = "pl", 1, "" }, { 'r', "remove", "Remove the current torrent(s)", "r", 0, NULL }, + { 'R', "remove-and-delete", "Remove the current torrent(s) and delete local data", + NULL, 0, NULL }, { 's', "start", "Start the current torrent(s)", "s", 0, NULL }, { 'S', "stop", "Stop the current torrent(s)", @@ -414,6 +416,12 @@ readargs( int argc, addIdArg( args, id ); break; + case 'R': + tr_bencDictAddStr( &top, "method", "torrent-remove" ); + addIdArg( args, id ); + tr_bencDictAddInt( args, "delete-local-data", 1 ); + break; + case 's': tr_bencDictAddStr( &top, "method", "torrent-start" ); addIdArg( args, id ); diff --git a/daemon/transmission-remote.1 b/daemon/transmission-remote.1 index 3042b701d..a9bf1a5a2 100644 --- a/daemon/transmission-remote.1 +++ b/daemon/transmission-remote.1 @@ -28,6 +28,7 @@ and .Op Fl pl Ar files .Op Fl pn Ar files .Op Fl r +.Op Fl R .Op Fl s | S .Op Fl t Ar all | Ar id | Ar hash .Op Fl u Ar number | Fl U @@ -134,6 +135,9 @@ Mark file(s) as low priority. .It Fl r Fl -remove Remove the current torrent(s). This does not delete the downloaded data. +.It Fl -remove-and-delete +Remove the current torrent(s) and delete their downloaded data. + .It Fl s Fl -start Start the current torrent(s) diff --git a/doc/rpc-spec.txt b/doc/rpc-spec.txt index 689abf0cb..6f193b598 100644 --- a/doc/rpc-spec.txt +++ b/doc/rpc-spec.txt @@ -68,7 +68,6 @@ Method name | libtransmission function --------------------+------------------------------------------------- - "torrent-remove" | tr_torrentRemove "torrent-start" | tr_torrentStart "torrent-stop" | tr_torrentStop "torrent-verify" | tr_torrentVerify @@ -293,6 +292,19 @@ form of one of 3.3's tr_info objects with the fields for id, name, and hashString. +3.5. Removing a Torrent + + Method name: "torrent-remove" + + Request arguments: + + string | value type & description + ---------------------------+------------------------------------------------- + "ids" | array torrent list, as described in 3.1 + "delete-local-data" | 'boolean' delete local data. (default: false) + + Response arguments: none + 4. Session Requests diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index 0b8d011d9..708757bfa 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -136,18 +136,21 @@ torrentStop( tr_handle * h, } static const char* -torrentRemove( tr_handle * h, - tr_benc * args_in, - tr_benc * args_out UNUSED ) +torrentRemove( tr_handle * h, + tr_benc * args_in, + tr_benc * args_out UNUSED ) { - int i, torrentCount; + int i; + int torrentCount; tr_torrent ** torrents = getTorrents( h, args_in, &torrentCount ); - for( i = 0; i < torrentCount; ++i ) + for( i=0; iinfo.fileCount; ++i ) + { + const tr_file * file = &tor->info.files[i]; + char * path = tr_buildPath( tor->downloadDir, file->name, NULL ); + tr_fdFileClose( path ); + unlink( path ); + tr_free( path ); + } +} + void tr_torrentStop( tr_torrent * tor ) { diff --git a/libtransmission/tr-getopt.c b/libtransmission/tr-getopt.c index f7fb5a443..6a47a74ab 100644 --- a/libtransmission/tr-getopt.c +++ b/libtransmission/tr-getopt.c @@ -47,8 +47,9 @@ getopts_usage_line( const tr_option * opt, const char * shortName = opt->shortName ? opt->shortName : ""; const char * arg = getArgName( opt ); - printf( " -%-*s --%-*s %-*s %s\n", shortWidth, shortName, - longWidth, longName, + printf( " %s%-*s %s%-*s %-*s %s\n", + (shortName && *shortName ? "-" : " "), shortWidth, shortName, + (longName && *longName ? "--" : " "), longWidth, longName, argWidth, arg, opt->description ); } diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 000a3a5c0..56e5b6a17 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -840,6 +840,9 @@ void tr_torrentStart( tr_torrent * torrent ); /** @brief Stop (pause) a torrent */ void tr_torrentStop( tr_torrent * torrent ); +/** @brief Deletes the torrent data stored on disk. */ +void tr_torrentDeleteLocalData( tr_torrent * torrent ); + /** * @brief Iterate through the torrents. *