commit f99c17f9596718e1ec4df58727f81bec72339110 from: Omar Polo date: Wed Nov 23 21:59:33 2022 UTC kamiftp: implement ‘rm’ command commit - 55e8c065589748eb51bc37751156a74c96051ed6 commit + f99c17f9596718e1ec4df58727f81bec72339110 blob - 1f3fe3b330c9607e0c96b8ed5b6eb5766cbbdda7 blob + 553ad8118c5fc9b3d53743ec7f13de1be0142495 --- kamiftp/ftp.c +++ kamiftp/ftp.c @@ -619,7 +619,23 @@ do_wstat(int fid, const struct np_stat *st) return NULL; } + +static char * +do_remove(int fid) +{ + char *errstr; + + tremove(fid); + do_send(); + recv_msg(); + if ((errstr = check(Rremove, iota_tag)) != NULL) + return errstr; + ASSERT_EMPTYBUF(); + + return NULL; +} + static size_t do_read(int fid, uint64_t off, uint32_t count, void *data) { @@ -1533,6 +1549,39 @@ cmd_rename(int argc, const char **argv) } do_clunk(nfid); +} + +static void +cmd_rm(int argc, const char **argv) +{ + struct qid qid; + char *errstr; + int nfid, miss; + + if (argc == 0) { + puts("usage: rm file ..."); + return; + } + + for (; *argv; ++argv, --argc) { + nfid = nextfid(); + errstr = walk_path(pwdfid, nfid, *argv, &miss, &qid); + if (errstr != NULL) { + printf("%s: %s\n", *argv, errstr); + free(errstr); + continue; + } + if (miss) { + printf("%s: not such file or directory\n", *argv); + continue; + } + + if ((errstr = do_remove(nfid)) != NULL) { + printf("%s: %s\n", *argv, errstr); + free(errstr); + continue; + } + } } static void @@ -1587,6 +1636,7 @@ excmd(int argc, const char **argv) {"put", cmd_put}, {"quit", cmd_bye}, {"rename", cmd_rename}, + {"rm", cmd_rm}, {"verbose", cmd_verbose}, }; size_t i; blob - 7a2e955493ea2859b0cc85000c46269522c2afbe blob + b75fa740fc8ed798c539ae2a64cfeae279c4cb39 --- kamiftp/kamiftp.1 +++ kamiftp/kamiftp.1 @@ -173,6 +173,8 @@ Renames to .Ar new-remote-name on the remote server. +.It Ic rm Ar +Remove the remote files. .It Ic verbose Oo Cm on | off Oc Print verbose information. Without arguments toggle the current state.