summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2006-10-08 09:12:29 +0000
committerRichard Nyberg <rnyberg@murmeldjur.se>2006-10-08 09:12:29 +0000
commita087071b45f08ef2074aa01f698c14648f3b36cf (patch)
treef990c5f981336fd502db9d128f05a97902f32b61
parenta497ca472a72db4cbe7d8d1831d7b71fe2480778 (diff)
downloadbtpd-a087071b45f08ef2074aa01f698c14648f3b36cf.tar.gz
btpd-a087071b45f08ef2074aa01f698c14648f3b36cf.zip
Make the del command work for active torrents too.
-rw-r--r--btpd/cli_if.c18
-rw-r--r--btpd/torrent.c2
-rw-r--r--btpd/torrent.h1
3 files changed, 14 insertions, 7 deletions
diff --git a/btpd/cli_if.c b/btpd/cli_if.c
index 4bb07c4..e35f222 100644
--- a/btpd/cli_if.c
+++ b/btpd/cli_if.c
@@ -291,8 +291,8 @@ cmd_del(struct cli *cli, int argc, const char *args)
     if (argc != 1)
         return IPC_COMMERR;
 
+    int ret;
     struct tlib *tl;
-    enum ipc_err code = IPC_OK;
     if (benc_isstr(args) && benc_strlen(args) == 20)
         tl = tlib_by_hash(benc_mem(args, NULL, NULL));
     else if (benc_isint(args))
@@ -301,13 +301,17 @@ cmd_del(struct cli *cli, int argc, const char *args)
         return IPC_COMMERR;
 
     if (tl == NULL)
-        code = IPC_ENOTENT;
-    else if (tl->tp != NULL)
-        code = IPC_ETACTIVE;
-    else
-        tlib_del(tl);
+        ret = write_code_buffer(cli, IPC_ENOTENT);
+    else {
+        ret = write_code_buffer(cli, IPC_OK);
+        if (tl->tp != NULL) {
+            tl->tp->delete = 1;
+            torrent_stop(tl->tp);
+        } else
+            tlib_del(tl);
+    }
 
-    return write_code_buffer(cli, code);
+    return ret;
 }
 
 static int
diff --git a/btpd/torrent.c b/btpd/torrent.c
index 99fb68d..427e147 100644
--- a/btpd/torrent.c
+++ b/btpd/torrent.c
@@ -160,6 +160,8 @@ torrent_kill(struct torrent *tp)
     net_kill(tp);
     cm_kill(tp);
     tp->tl->tp = NULL;
+    if (tp->delete)
+        tlib_del(tp->tl);
     mi_free_files(tp->nfiles, tp->files);
     free(tp);
     if (m_ntorrents == 0)
diff --git a/btpd/torrent.h b/btpd/torrent.h
index 9181109..9fa3792 100644
--- a/btpd/torrent.h
+++ b/btpd/torrent.h
@@ -15,6 +15,7 @@ struct torrent {
 
     char relpath[RELPATH_SIZE];
     enum torrent_state state;
+    int delete;
 
     struct content *cm;
     struct tracker *tr;