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

Function cbm_runtime_settings_init

src/cli/runtime_settings.c:530–569  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

528}
529
530bool cbm_runtime_settings_init(const char *cache) {
531 char canonical[SETTINGS_PATH_CAP];
532 if (!canonical_cache_path(cache, canonical, true))
533 return false;
534 if (initialized)
535 return strcmp(canonical, initial_cache) == 0;
536 char path[SETTINGS_PATH_CAP];
537 if (snprintf(path, sizeof(path), "%s/_config.db", canonical) >= (int)sizeof(path))
538 return false;
539 sqlite3 *db = NULL;
540 if (cbm_file_exists(path)) {
541 /* The snapshot read happens before individual optional tables are
542 * queried; failing here exits the whole process. Hook clients skip
543 * this init. */
544 db = settings_read_snapshot(path);
545 if (!db)
546 return false;
547 }
548 for (size_t i = 0; i < SETTINGS_COUNT; i++) {
549 bool saved = false;
550 const char *source = NULL;
551 char temporary[SETTINGS_VALUE_CAP];
552 const char *value = desired_value(db, &settings[i], temporary, &saved, &source);
553 initial_present[i] = value != NULL;
554 if (value)
555 (void)snprintf(initial_values[i], SETTINGS_VALUE_CAP, "%s", value);
556 environment_overridden[i] = saved && settings[i].storage == SET_ENV;
557 if (environment_overridden[i])
558 (void)snprintf(environment_values[i], SETTINGS_VALUE_CAP, "%s", value);
559 }
560 bool ok = !db || sqlite3_exec(db, "COMMIT", NULL, NULL, NULL) == SQLITE_OK;
561 if (db)
562 sqlite3_close(db);
563 if (!ok)
564 return false;
565 (void)snprintf(initial_cache, sizeof(initial_cache), "%s", canonical);
566 cbm_set_environment_resolver(resolve_environment);
567 initialized = true;
568 return true;
569}
570
571static void json_string(yyjson_mut_doc *doc, yyjson_mut_val *object, const char *key,
572 const char *value) {

Callers 2

mainFunction · 0.85

Calls 5

canonical_cache_pathFunction · 0.85
cbm_file_existsFunction · 0.85
settings_read_snapshotFunction · 0.85
desired_valueFunction · 0.85

Tested by

no test coverage detected