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

Function write_hook_event_array

src/cli/cli.c:4755–4779  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4753#endif
4754
4755static int write_hook_event_array(const char *settings_path, const char *hook_event,
4756 yyjson_mut_doc *doc, yyjson_mut_val *event_arr,
4757 const char *expected_content, size_t expected_length) {
4758 static const char *const hooks_path[] = {"hooks"};
4759#ifdef CBM_JSON_LIKE_ENABLE_TEST_API
4760 if (cbm_hook_json_prewrite_test_hook) {
4761 cbm_hook_json_prewrite_test_hook(settings_path, cbm_hook_json_prewrite_test_context);
4762 }
4763#endif
4764 if (yyjson_mut_arr_size(event_arr) == 0U) {
4765 return cbm_json_like_remove_entry_if_unchanged(settings_path, hooks_path, 1U, hook_event,
4766 expected_content, expected_length) == 0
4767 ? CLI_OK
4768 : CLI_ERR;
4769 }
4770 yyjson_mut_doc_set_root(doc, event_arr);
4771 char *event_json = yyjson_mut_write(doc, YYJSON_WRITE_PRETTY, NULL);
4772 if (!event_json) {
4773 return CLI_ERR;
4774 }
4775 int rc = cbm_json_like_upsert_entry_if_unchanged(settings_path, hooks_path, 1U, hook_event,
4776 event_json, expected_content, expected_length);
4777 free(event_json);
4778 return rc == 0 ? CLI_OK : CLI_ERR;
4779}
4780
4781static int upsert_hooks_json(hooks_upsert_args_t args) {
4782 const char *settings_path = args.settings_path;

Callers 2

upsert_hooks_jsonFunction · 0.85
remove_hooks_jsonFunction · 0.85

Tested by

no test coverage detected