From 058c8983f562d81cc9cf4d4547e337d34e2e3bf1 Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Tue, 25 Aug 2015 20:22:50 +0200 Subject: [PATCH] ocat: [NEW] $OCAT_STORAGEDIR or --storage (defaults to ./store) --- Makefile | 6 +++--- README.md | 2 +- config.h.example | 8 -------- misc.h | 2 ++ ocat.c | 10 ++++++++++ storage.c | 2 ++ 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index ceb62c9..b4f8adf 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,8 @@ endif all: ot-recorder ocat -ot-recorder: ot-recorder.c json.o utarray.h utstring.h geo.o geohash.o mkpath.o file.o safewrite.o base64.o ghash.o config.h udata.h misc.o util.o - $(CC) $(CFLAGS) ot-recorder.c -o ot-recorder json.o geo.o geohash.o mkpath.o file.o safewrite.o base64.o ghash.o misc.o util.o $(LIBS) +ot-recorder: ot-recorder.c json.o utarray.h utstring.h geo.o geohash.o mkpath.o file.o safewrite.o base64.o ghash.o config.h udata.h misc.o util.o storage.o + $(CC) $(CFLAGS) ot-recorder.c -o ot-recorder json.o geo.o geohash.o mkpath.o file.o safewrite.o base64.o ghash.o misc.o util.o storage.o $(LIBS) geo.o: geo.h geo.c udata.h Makefile config.mk config.h geohash.o: geohash.h geohash.c udata.h Makefile config.mk @@ -29,7 +29,7 @@ ocat: ocat.o storage.o json.o geohash.o ghash.o mkpath.o util.o $(CC) $(CFLAGS) -o ocat ocat.o storage.o json.o geohash.o ghash.o mkpath.o util.o $(LIBS) ocat.o: ocat.c storage.h -storage.o: storage.c storage.h config.h +storage.o: storage.c storage.h config.h util.h clean: rm -f *.o diff --git a/README.md b/README.md index 3784c85..2c1ef06 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ We took a number of decisions for the design of the recorder and its utilities: ## Storage -As mentioned earlier, data is stored in files, and these files are relative to `STORAGEDIR` (compiled into the programs). In particular, the following directory structure can exist, whereby directories are created as needed by the _recorder_: +As mentioned earlier, data is stored in files, and these files are relative to `STORAGEDIR` (compiled into the programs or specified as an option). In particular, the following directory structure can exist, whereby directories are created as needed by the _recorder_: * `cards/`, optional, contain user cards. * `ghash/`, unless disabled, reverse Geo data is collected in files named after the geohash in directories named with the first three characters of the geohash. diff --git a/config.h.example b/config.h.example index 22309cb..d2b5995 100644 --- a/config.h.example +++ b/config.h.example @@ -1,11 +1,3 @@ -/* - * This is the top-level directory you create; ot-recorder - * stores files below this hierarchy and creates directories - * therin by itself. Note that the user running `ot-recorder' - * must be granted write access (rwx) - */ - -#define STORAGEDIR "/path/to/store" /* * 1 => 5,009.4km x 4,992.6km diff --git a/misc.h b/misc.h index 8138085..13888e7 100644 --- a/misc.h +++ b/misc.h @@ -4,6 +4,8 @@ #include #include "udata.h" +extern char STORAGEDIR[]; + #ifndef TRUE # define TRUE (1) # define FALSE (0) diff --git a/ocat.c b/ocat.c index 3d839da..c564a9c 100644 --- a/ocat.c +++ b/ocat.c @@ -7,6 +7,7 @@ #include "json.h" #include "storage.h" #include "util.h" +#include "misc.h" typedef enum { TABULAR = 0, @@ -123,6 +124,7 @@ void usage(char *prog) printf(" tabular\n"); printf(" --last -L JSON object with last users\n"); printf(" --killdata requires -u and -d\n"); + printf(" --storage -S storage dir (./store)\n"); exit(1); } @@ -154,6 +156,10 @@ int main(int argc, char **argv) } } + if ((p = getenv("OCAT_STORAGEDIR")) != NULL) { + strcpy(STORAGEDIR, p); + } + time(&now); while (1) { @@ -165,6 +171,7 @@ int main(int argc, char **argv) { "from", required_argument, 0, 'F'}, { "to", required_argument, 0, 'T'}, { "format", required_argument, 0, 'f'}, + { "storage", required_argument, 0, 'S'}, { "last", no_argument, 0, 'L'}, { "killdata", no_argument, 0, 'K'}, {0, 0, 0, 0} @@ -188,6 +195,9 @@ int main(int argc, char **argv) case 'F': time_from = strdup(optarg); break; + case 'S': + strcpy(STORAGEDIR, optarg); + break; case 'T': time_to = strdup(optarg); break; diff --git a/storage.c b/storage.c index c2f1e5c..d1317c0 100644 --- a/storage.c +++ b/storage.c @@ -16,6 +16,8 @@ #include "util.h" #include "udata.h" +char STORAGEDIR[BUFSIZ] = "./store"; + #define LINESIZE 8192 int ghash_readcache(struct udata *ud, char *ghash, UT_string *addr, UT_string *cc);