X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Ffcache.c;h=2f7648663463534008d102f10150a3b982041831;hb=60892f2ef45fa1ee656e1a00cac0578f9d6f9536;hp=89c66d45e07b9098da104a9a941027fe47779f0b;hpb=be68914bbcbfde6dbc51e20075691afbab3c2489;p=ppastats.git diff --git a/src/fcache.c b/src/fcache.c index 89c66d4..2f76486 100644 --- a/src/fcache.c +++ b/src/fcache.c @@ -59,12 +59,15 @@ static char *key_to_path(const char *key) char *path; const char *dir; + if (!key || !*key || *key != '/') + return NULL; + dir = get_cache_dir(); if (!dir) return NULL; - path = malloc(strlen(dir) + 1 + strlen(key) + strlen("/data.json") + 1); - sprintf(path, "%s%s/data.json", dir, key); + path = malloc(strlen(dir) + 1 + strlen(key) + strlen("/data") + 1); + sprintf(path, "%s%s.data", dir, key); return path; } @@ -74,22 +77,24 @@ char *fcache_get(const char *key) char *path, *content; path = key_to_path(key); - if (!path) + if (!path) { + log_err(_("file cache, invalid key: %s"), key); return NULL; + } content = file_get_content(path); - + if (content) log_debug(_("file cache hit %s"), key); else log_debug(_("file cache miss %s %s"), key, path); - + free(path); - + return content; } - -void fcache_put(const char *key, char *value) + +void fcache_put(const char *key, const char *value) { char *path, *dir, *tmp; FILE *f;