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);