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

Function cbm_config_open

src/cli/cli.c:6377–6412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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