MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_config_open

Function cbm_config_open

src/cli/cli.c:6460–6495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6458};
6459
6460cbm_config_t *cbm_config_open(const char *cache_dir) {
6461 if (!cache_dir) {
6462 return NULL;
6463 }
6464
6465 char dbpath[CLI_BUF_1K];
6466 snprintf(dbpath, sizeof(dbpath), "%s/_config.db", cache_dir);
6467
6468 /* Ensure directory exists */
6469 mkdirp(cache_dir, DIR_PERMS);
6470
6471 sqlite3 *db = NULL;
6472 if (sqlite3_open(dbpath, &db) != SQLITE_OK) {
6473 if (db) {
6474 sqlite3_close(db);
6475 }
6476 return NULL;
6477 }
6478
6479 /* Create table if not exists */
6480 const char *sql = "CREATE TABLE IF NOT EXISTS config (key TEXT PRIMARY KEY, value TEXT)";
6481 char *err_msg = NULL;
6482 if (sqlite3_exec(db, sql, NULL, NULL, &err_msg) != SQLITE_OK) {
6483 sqlite3_free(err_msg);
6484 sqlite3_close(db);
6485 return NULL;
6486 }
6487
6488 cbm_config_t *cfg = calloc(CBM_ALLOC_ONE, sizeof(*cfg));
6489 if (!cfg) {
6490 sqlite3_close(db);
6491 return NULL;
6492 }
6493 cfg->db = db;
6494 return cfg;
6495}
6496
6497void cbm_config_close(cbm_config_t *cfg) {
6498 if (!cfg) {

Callers 8

cbm_cmd_configFunction · 0.85
handle_ui_configFunction · 0.85
host_state_prepareFunction · 0.85
test_cli.cFile · 0.85
test_httpd.cFile · 0.85

Calls 1

mkdirpFunction · 0.85

Tested by 2