From a087071b45f08ef2074aa01f698c14648f3b36cf Mon Sep 17 00:00:00 2001 From: Richard Nyberg Date: Sun, 8 Oct 2006 09:12:29 +0000 Subject: Make the del command work for active torrents too. --- btpd/cli_if.c | 18 +++++++++++------- btpd/torrent.c | 2 ++ btpd/torrent.h | 1 + 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; -- cgit 1.4.1