Skip to content
Snippets Groups Projects
Commit 3037dc0e authored by Marek Vavruša's avatar Marek Vavruša
Browse files

cache: create env if not exists

parent 123a847d
Branches
Tags
No related merge requests found
#include <assert.h>
#include <time.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <lmdb.h>
#include <libknot/internal/mempattern.h>
......@@ -28,6 +31,11 @@ struct kr_txn
/* MDB access */
static int create_env_dir(const char *path)
{
return mkdir(path, 0770);
}
static int dbase_open(struct kr_cache *cache, const char *handle)
{
int ret = mdb_env_create(&cache->env);
......@@ -35,6 +43,12 @@ static int dbase_open(struct kr_cache *cache, const char *handle)
return ret;
}
ret = create_env_dir(handle);
if (ret != 0) {
mdb_env_close(cache->env);
return ret;
}
ret = mdb_env_open(cache->env, handle, 0, 0644);
if (ret != 0) {
mdb_env_close(cache->env);
......
......@@ -16,7 +16,7 @@ int kr_context_init(struct kr_context *ctx, mm_ctx_t *mm)
ctx->cache = kr_cache_open("/tmp/kresolved", 0, mm);
if (ctx->cache == NULL) {
fprintf(stderr, "Cache directory '/tmp/kresolved' not exists.\n");
fprintf(stderr, "Cache directory '/tmp/kresolved' not exists, exitting.\n");
assert(ctx->cache);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment