From 78ff4b41bbbc602693de0159b69db4e0874e7fbe Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Sat, 15 Aug 2015 08:59:21 +0200 Subject: [PATCH] subdirectorize ghash store closes #5 --- ghash.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ghash.c b/ghash.c index ad75b67..849e433 100644 --- a/ghash.c +++ b/ghash.c @@ -105,7 +105,7 @@ int ghash_readcache(struct udata *ud, char *ghash, UT_string *addr, UT_string *c if (ud->usefiles) { /* if ghash file is available, read cc:addr into that */ - snprintf(gfile, BUFSIZ, "%s/ghash/%s.json", JSONDIR, ghash); + snprintf(gfile, BUFSIZ, "%s/ghash/%-3.3s/%s.json", JSONDIR, ghash, ghash); fprintf(stderr, "Reading GhashCache from %s\n", gfile); if ((fp = fopen(gfile, "r")) != NULL) { @@ -168,7 +168,12 @@ void ghash_storecache(struct udata *ud, JsonNode *geo, char *ghash, char *addr, json_append_member(geo, "cc", json_mkstring(ghash)); if ((js = json_stringify(geo, NULL)) != NULL) { - snprintf(gfile, BUFSIZ, "%s/ghash/%s.json", JSONDIR, ghash); + snprintf(gfile, BUFSIZ, "%s/ghash/%-3.3s", JSONDIR, ghash); + if (mkpath(gfile) != 0) { + perror(gfile); + return; + } + snprintf(gfile, BUFSIZ, "%s/ghash/%-3.3s/%s.json", JSONDIR, ghash, ghash); if ((fp = fopen(gfile, "w")) != NULL) { fprintf(fp, "%s\n", js);