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

Function write_hook_event_array

src/cli/cli.c:4014–4038  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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