From: simon Date: Sun, 2 Nov 2008 14:15:24 +0000 (+0000) Subject: New operation mode to remove the data file. Now you can get a nicely X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/agedu/commitdiff_plain/355c3af79e91b2c650648015e48708b81ff4cb7e New operation mode to remove the data file. Now you can get a nicely self-contained scan-and-web-server in a single run without leaving detritus, by running "agedu -s -w -R". git-svn-id: svn://svn.tartarus.org/sgt/agedu@8258 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/TODO b/TODO index 0f94d49..cfd5577 100644 --- a/TODO +++ b/TODO @@ -13,9 +13,6 @@ Before it's non-embarrassingly releasable: too, if it's available and O_NOATIME is too. * what do we do elsewhere about _GNU_SOURCE? - - New mode: --remove, to destroy the data file. Handy for - totally self-contained usage: "-s . -w -R". - - man page, --version. Future possibilities: diff --git a/agedu.c b/agedu.c index 7a9b164..caef604 100644 --- a/agedu.c +++ b/agedu.c @@ -284,6 +284,8 @@ static void text_query(const void *mappedfile, const char *querydir, HELPARG("subdir") HELPOPT("print an HTML report on a subdirectory") \ NOVAL(HTTPD) SHORT(w) LONG(web) LONG(server) LONG(httpd) \ HELPOPT("serve HTML reports from a temporary web server") \ + NOVAL(REMOVE) SHORT(R) LONG(remove) LONG(delete) LONG(unlink) \ + HELPOPT("remove the index file") \ HELPPFX("options") \ VAL(DATAFILE) SHORT(f) LONG(file) \ HELPARG("filename") HELPOPT("[most modes] specify index file") \ @@ -456,7 +458,7 @@ int main(int argc, char **argv) const struct trie_file *tf; char *filename = PNAME ".dat"; int doing_opts = 1; - enum { TEXT, HTML, SCAN, DUMP, SCANDUMP, LOAD, HTTPD }; + enum { TEXT, HTML, SCAN, DUMP, SCANDUMP, LOAD, HTTPD, REMOVE }; struct action { int mode; char *arg; @@ -690,6 +692,15 @@ int main(int argc, char **argv) actions[nactions].arg = NULL; nactions++; break; + case OPT_REMOVE: + if (nactions >= actionsize) { + actionsize = nactions * 3 / 2 + 16; + actions = sresize(actions, actionsize, struct action); + } + actions[nactions].mode = REMOVE; + actions[nactions].arg = NULL; + nactions++; + break; case OPT_PROGRESS: progress = 2; break; @@ -1188,6 +1199,12 @@ int main(int argc, char **argv) pcfg.oldest = htmloldest; pcfg.newest = htmlnewest; run_httpd(mappedfile, auth, &dcfg, &pcfg); + } else if (mode == REMOVE) { + if (remove(filename) < 0) { + fprintf(stderr, "%s: %s: remove: %s\n", PNAME, filename, + strerror(errno)); + return 1; + } } }