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

Function cbm_config_open

src/cli/cli.c:6383–6418  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6381};
6382
6383cbm_config_t *cbm_config_open(const char *cache_dir) {
6384 if (!cache_dir) {
6385 return NULL;
6386 }
6387
6388 char dbpath[CLI_BUF_1K];
6389 snprintf(dbpath, sizeof(dbpath), "%s/_config.db", cache_dir);
6390
6391 /* Ensure directory exists */
6392 mkdirp(cache_dir, DIR_PERMS);
6393
6394 sqlite3 *db = NULL;
6395 if (sqlite3_open(dbpath, &db) != SQLITE_OK) {
6396 if (db) {
6397 sqlite3_close(db);
6398 }
6399 return NULL;
6400 }
6401
6402 /* Create table if not exists */
6403 const char *sql = "CREATE TABLE IF NOT EXISTS config (key TEXT PRIMARY KEY, value TEXT)";
6404 char *err_msg = NULL;
6405 if (sqlite3_exec(db, sql, NULL, NULL, &err_msg) != SQLITE_OK) {
6406 sqlite3_free(err_msg);
6407 sqlite3_close(db);
6408 return NULL;
6409 }
6410
6411 cbm_config_t *cfg = calloc(CBM_ALLOC_ONE, sizeof(*cfg));
6412 if (!cfg) {
6413 sqlite3_close(db);
6414 return NULL;
6415 }
6416 cfg->db = db;
6417 return cfg;
6418}
6419
6420void cbm_config_close(cbm_config_t *cfg) {
6421 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