Browse Source

Make the del command work for active torrents too.

master
Richard Nyberg 18 years ago
parent
commit
a087071b45
3 changed files with 14 additions and 7 deletions
  1. +11
    -7
      btpd/cli_if.c
  2. +2
    -0
      btpd/torrent.c
  3. +1
    -0
      btpd/torrent.h

+ 11
- 7
btpd/cli_if.c View File

@@ -291,8 +291,8 @@ cmd_del(struct cli *cli, int argc, const char *args)
if (argc != 1) if (argc != 1)
return IPC_COMMERR; return IPC_COMMERR;


int ret;
struct tlib *tl; struct tlib *tl;
enum ipc_err code = IPC_OK;
if (benc_isstr(args) && benc_strlen(args) == 20) if (benc_isstr(args) && benc_strlen(args) == 20)
tl = tlib_by_hash(benc_mem(args, NULL, NULL)); tl = tlib_by_hash(benc_mem(args, NULL, NULL));
else if (benc_isint(args)) else if (benc_isint(args))
@@ -301,13 +301,17 @@ cmd_del(struct cli *cli, int argc, const char *args)
return IPC_COMMERR; return IPC_COMMERR;


if (tl == NULL) 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 static int


+ 2
- 0
btpd/torrent.c View File

@@ -160,6 +160,8 @@ torrent_kill(struct torrent *tp)
net_kill(tp); net_kill(tp);
cm_kill(tp); cm_kill(tp);
tp->tl->tp = NULL; tp->tl->tp = NULL;
if (tp->delete)
tlib_del(tp->tl);
mi_free_files(tp->nfiles, tp->files); mi_free_files(tp->nfiles, tp->files);
free(tp); free(tp);
if (m_ntorrents == 0) if (m_ntorrents == 0)


+ 1
- 0
btpd/torrent.h View File

@@ -15,6 +15,7 @@ struct torrent {


char relpath[RELPATH_SIZE]; char relpath[RELPATH_SIZE];
enum torrent_state state; enum torrent_state state;
int delete;


struct content *cm; struct content *cm;
struct tracker *tr; struct tracker *tr;


Loading…
Cancel
Save