From d0c66fe817ca0e5bf444e9aee28a0fac0ca9631a Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Thu, 16 Feb 2023 14:57:01 +0800 Subject: [PATCH] Force server database path Use path relative to server executable instead of current working directory. --- src/packages/server/db/IZ_repo.c | 7 ++++++- src/packages/server/db/IZ_repo.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/packages/server/db/IZ_repo.c b/src/packages/server/db/IZ_repo.c index 9168a53..3f3a615 100644 --- a/src/packages/server/db/IZ_repo.c +++ b/src/packages/server/db/IZ_repo.c @@ -40,7 +40,12 @@ IZ_ProcedureResult IZ_RepoInitialize(IZ_RepoState* state, const char* config_pat if (IZ_RepoInitializeConfig(state, config_path, argc, argv) < 0) { return -2; } - sqlite3_open_v2(state->config.path, &state->db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); + const char* base_path = SDL_GetBasePath(); + char config_path_dir[128]; + IZ_memcpy(config_path_dir, 128, base_path, 128); + IZ_strcat(config_path_dir, 128, "/"); + IZ_strcat(config_path_dir, 128, state->config.path); + sqlite3_open_v2(config_path_dir, &state->db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); return 0; } diff --git a/src/packages/server/db/IZ_repo.h b/src/packages/server/db/IZ_repo.h index c1cfb10..a9cf69d 100644 --- a/src/packages/server/db/IZ_repo.h +++ b/src/packages/server/db/IZ_repo.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "../../common/IZ_common.h" #include "../../config/IZ_config.h" #include "../../stdinc/IZ_string.h"