subdirectorize ghash store

closes #5
This commit is contained in:
Jan-Piet Mens
2015-08-15 08:59:21 +02:00
parent 006773f19b
commit 78ff4b41bb

View File

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