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

Function write_hook_event_array

src/cli/cli.c:4008–4032  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4006#endif
4007
4008static int write_hook_event_array(const char *settings_path, const char *hook_event,
4009 yyjson_mut_doc *doc, yyjson_mut_val *event_arr,
4010 const char *expected_content, size_t expected_length) {
4011 static const char *const hooks_path[] = {"hooks"};
4012#ifdef CBM_JSON_LIKE_ENABLE_TEST_API
4013 if (cbm_hook_json_prewrite_test_hook) {
4014 cbm_hook_json_prewrite_test_hook(settings_path, cbm_hook_json_prewrite_test_context);
4015 }
4016#endif
4017 if (yyjson_mut_arr_size(event_arr) == 0U) {
4018 return cbm_json_like_remove_entry_if_unchanged(settings_path, hooks_path, 1U, hook_event,
4019 expected_content, expected_length) == 0
4020 ? CLI_OK
4021 : CLI_ERR;
4022 }
4023 yyjson_mut_doc_set_root(doc, event_arr);
4024 char *event_json = yyjson_mut_write(doc, YYJSON_WRITE_PRETTY, NULL);
4025 if (!event_json) {
4026 return CLI_ERR;
4027 }
4028 int rc = cbm_json_like_upsert_entry_if_unchanged(settings_path, hooks_path, 1U, hook_event,
4029 event_json, expected_content, expected_length);
4030 free(event_json);
4031 return rc == 0 ? CLI_OK : CLI_ERR;
4032}
4033
4034static int upsert_hooks_json(hooks_upsert_args_t args) {
4035 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