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

Function cbm_config_open

src/cli/cli.c:7395–7433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7393};
7394
7395cbm_config_t *cbm_config_open(const char *cache_dir) {
7396 if (!cache_dir) {
7397 return NULL;
7398 }
7399
7400 char dbpath[CLI_BUF_1K];
7401 snprintf(dbpath, sizeof(dbpath), "%s/" CBM_CONFIG_DB_FILENAME, cache_dir);
7402
7403 /* Ensure directory exists */
7404 mkdirp(cache_dir, DIR_PERMS);
7405
7406 sqlite3 *db = NULL;
7407 if (sqlite3_open(dbpath, &db) != SQLITE_OK) {
7408 if (db) {
7409 sqlite3_close(db);
7410 }
7411 return NULL;
7412 }
7413 /* Another process mid-commit is waited out; failing here failed every
7414 * settings write behind it, the daemon's UI save included. */
7415 cbm_runtime_settings_wait_for_writers(db);
7416
7417 /* Create table if not exists */
7418 const char *sql = "CREATE TABLE IF NOT EXISTS config (key TEXT PRIMARY KEY, value TEXT)";
7419 char *err_msg = NULL;
7420 if (sqlite3_exec(db, sql, NULL, NULL, &err_msg) != SQLITE_OK) {
7421 sqlite3_free(err_msg);
7422 sqlite3_close(db);
7423 return NULL;
7424 }
7425
7426 cbm_config_t *cfg = calloc(CBM_ALLOC_ONE, sizeof(*cfg));
7427 if (!cfg) {
7428 sqlite3_close(db);
7429 return NULL;
7430 }
7431 cfg->db = db;
7432 return cfg;
7433}
7434
7435void cbm_config_close(cbm_config_t *cfg) {
7436 if (!cfg) {

Callers 15

cbm_cmd_configFunction · 0.85
settings_openFunction · 0.85
load_index_policyFunction · 0.85
handle_ui_configFunction · 0.85
host_state_prepareFunction · 0.85
test_cli.cFile · 0.85
test_mcp.cFile · 0.85
autoindex_limit_probeFunction · 0.85

Calls 2

mkdirpFunction · 0.85