(daemon) #1510: kysucix's patch to give an option to delete local data via RPC when removing a torrent.

This commit is contained in:
Charles Kerr 2008-12-09 17:01:49 +00:00
parent 519b4d3f5e
commit a33b78fc53
7 changed files with 57 additions and 11 deletions

View File

@ -99,6 +99,8 @@ static tr_option opts[] =
"pl", 1, "<files>" },
{ '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 );

View File

@ -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)

View File

@ -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

View File

@ -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; i<torrentCount; ++i )
{
tr_torrent * tor = torrents[i];
const tr_rpc_callback_status status = notify(
h, TR_RPC_TORRENT_REMOVING, tor );
tr_torrent * tor = torrents[i];
const tr_rpc_callback_status status = notify( h, TR_RPC_TORRENT_REMOVING, tor );
int64_t deleteFlag;
if( tr_bencDictFindInt( args_in, "delete-local-data", &deleteFlag ) && deleteFlag )
tr_torrentDeleteLocalData( tor );
if( !( status & TR_RPC_NOREMOVE ) )
tr_torrentRemove( tor );
}

View File

@ -1197,6 +1197,21 @@ stopTorrent( void * vtor )
}
}
void
tr_torrentDeleteLocalData( tr_torrent * tor )
{
tr_file_index_t i;
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 );
unlink( path );
tr_free( path );
}
}
void
tr_torrentStop( tr_torrent * tor )
{

View File

@ -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 );
}

View File

@ -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.
*