From ca21c1f230ba83ad5b5ba35584b315ac58d01938 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Tue, 20 Oct 2015 21:06:01 +0000 Subject: [PATCH] Always invoke async RPC callback, even if operation failed to start --- libtransmission/rpcimpl.c | 205 +++++++++++++++++++------------------- 1 file changed, 100 insertions(+), 105 deletions(-) diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index 6da1a9ff0..9d514a2d4 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -1336,35 +1336,30 @@ torrentSetLocation (tr_session * session, tr_variant * args_out UNUSED, struct tr_rpc_idle_data * idle_data UNUSED) { - const char * errmsg = NULL; const char * location = NULL; assert (idle_data == NULL); if (!tr_variantDictFindStr (args_in, TR_KEY_location, &location, NULL)) - { - errmsg = "no location"; - } - else - { - bool move; - int i, torrentCount; - tr_torrent ** torrents = getTorrents (session, args_in, &torrentCount); + return "no location"; - if (!tr_variantDictFindBool (args_in, TR_KEY_move, &move)) - move = false; + bool move; + int i, torrentCount; + tr_torrent ** torrents = getTorrents (session, args_in, &torrentCount); - for (i=0; idata = idle_data; + d->ctor = ctor; + tr_webRunWithCookies (session, filename, cookies, gotMetadataFromURL, d); + } + else + { + char * fname = tr_strstrip (tr_strdup (filename)); + + if (fname == NULL) + { + size_t len; + char * metainfo = tr_base64_decode_str (metainfo_base64, &len); + tr_ctorSetMetainfo (ctor, (uint8_t*)metainfo, len); + tr_free (metainfo); + } + else if (!strncmp (fname, "magnet:?", 8)) { - struct add_torrent_idle_data * d = tr_new0 (struct add_torrent_idle_data, 1); - d->data = idle_data; - d->ctor = ctor; - tr_webRunWithCookies (session, filename, cookies, gotMetadataFromURL, d); + tr_ctorSetMetainfoFromMagnetLink (ctor, fname); } else { - char * fname = tr_strstrip (tr_strdup (filename)); - - if (fname == NULL) - { - size_t len; - char * metainfo = tr_base64_decode_str (metainfo_base64, &len); - tr_ctorSetMetainfo (ctor, (uint8_t*)metainfo, len); - tr_free (metainfo); - } - else if (!strncmp (fname, "magnet:?", 8)) - { - tr_ctorSetMetainfoFromMagnetLink (ctor, fname); - } - else - { - tr_ctorSetMetainfoFromFile (ctor, fname); - } - - addTorrentImpl (idle_data, ctor); - - tr_free (fname); + tr_ctorSetMetainfoFromFile (ctor, fname); } + addTorrentImpl (idle_data, ctor); + + tr_free (fname); } return NULL; @@ -2258,7 +2249,11 @@ tr_rpc_request_exec_json (tr_session * session, data->args_out = tr_variantDictAddDict (data->response, TR_KEY_arguments, 0); data->callback = callback; data->callback_user_data = callback_user_data; - (*methods[i].func)(session, args_in, data->args_out, data); + result = (*methods[i].func)(session, args_in, data->args_out, data); + + /* Async operation failed prematurely? Invoke callback or else client will not get a reply */ + if (result != NULL) + tr_idle_function_done (data, result); } } -- 2.40.0