]> granicus.if.org Git - transmission/commitdiff
(daemon) #1510: kysucix's patch to give an option to delete local data via RPC when...
authorCharles Kerr <charles@transmissionbt.com>
Tue, 9 Dec 2008 17:01:49 +0000 (17:01 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Tue, 9 Dec 2008 17:01:49 +0000 (17:01 +0000)
daemon/remote.c
daemon/transmission-remote.1
doc/rpc-spec.txt
libtransmission/rpcimpl.c
libtransmission/torrent.c
libtransmission/tr-getopt.c
libtransmission/transmission.h

index 0e8507ec8e43ed48c7f15a89ade94370e3544883..2c5c537d4ffb3bf0e5b1b53cc121f0cf89484c9d 100644 (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 );
index 3042b701d014e85d06ac0b73a124bcd7ccb2fdf0..a9bf1a5a2b37357d6db27c0645f45a42412adda9 100644 (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)
 
index 689abf0cbae350b54ac4b702c2f8eada7bd9f6cd..6f193b5988bb9da1b9fe905a6fe6212081dc7c81 100644 (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
                        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
 
index 0b8d011d9fee287f287098ddd1279ce32f08d0ad..708757bfab95d73888dcc0fbae5f5069392dd5f6 100644 (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 );
     }
index e8a2b14dffe8396d51ea79b0cba7e31c60cf9edc..c31690a45d182bec29af3eed106e22cca374ad9c 100644 (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 )
 {
index f7fb5a443141534a7f91f467e00e4a4a2ae8ceb7..6a47a74ab846e35634132f6b547548b3974b142d 100644 (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 );
 }
index 000a3a5c0b6e6e27bb1bc74c91d856e16cc0888e..56e5b6a171a9ccfc670334def8c8af409063f7d7 100644 (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.
  *