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

Function cbm_ui_config_save

src/ui/config.c:389–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

387#endif
388
389bool cbm_ui_config_save(const cbm_ui_config_t *cfg) {
390 if (cfg && cbm_runtime_settings_initialized()) {
391 return cbm_runtime_settings_save_ui(cfg->ui_enabled, cfg->ui_port);
392 }
393 if (!cfg || cfg->ui_port <= 0 || cfg->ui_port > 65535) {
394 cbm_log_error("ui.config.write_fail", "reason", "invalid_config");
395 return false;
396 }
397 char path[CBM_SZ_1K];
398 cbm_ui_config_path(path, (int)sizeof(path));
399
400 /* Ensure directory exists (recursive) */
401 char dir[CBM_SZ_1K];
402 bool directory_ready = config_parent_directory(path, dir, sizeof(dir));
403 if (directory_ready && !cbm_is_dir(dir)) {
404 directory_ready = cbm_mkdir_p_ex(dir, 0750, CBM_MKDIR_FOLLOW_OWNED) || cbm_is_dir(dir);
405 }
406 if (!directory_ready) {
407 cbm_log_error("ui.config.write_fail", "path", path, "reason", "create_directory");
408 return false;
409 }
410
411 yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
412 yyjson_mut_val *root = doc ? yyjson_mut_obj(doc) : NULL;
413 bool serialized = doc && root;
414 if (serialized) {
415 yyjson_mut_doc_set_root(doc, root);
416 serialized = yyjson_mut_obj_add_bool(doc, root, "ui_enabled", cfg->ui_enabled) &&
417 yyjson_mut_obj_add_int(doc, root, "ui_port", cfg->ui_port);
418 }
419
420 size_t json_len = 0;
421 char *json = serialized ? yyjson_mut_write(doc, YYJSON_WRITE_PRETTY, &json_len) : NULL;
422 if (doc) {
423 yyjson_mut_doc_free(doc);
424 }
425
426 if (!json) {
427 cbm_log_error("ui.config.write_fail", "reason", "serialize");
428 return false;
429 }
430
431 bool saved = config_write_atomic(path, json, json_len);
432 free(json);
433 if (!saved) {
434 cbm_log_error("ui.config.write_fail", "path", path, "reason", "atomic_publish");
435 return false;
436 }
437
438 cbm_log_debug("ui.config.saved", "path", path);
439 return true;
440}

Callers 5

config_ui_writeFunction · 0.85
test_ui.cFile · 0.85

Calls 7

cbm_ui_config_pathFunction · 0.85
config_parent_directoryFunction · 0.85
cbm_is_dirFunction · 0.85
cbm_mkdir_p_exFunction · 0.85
config_write_atomicFunction · 0.85

Tested by

no test coverage detected