| 4068 | #endif |
| 4069 | |
| 4070 | static int write_hook_event_array(const char *settings_path, const char *hook_event, |
| 4071 | yyjson_mut_doc *doc, yyjson_mut_val *event_arr, |
| 4072 | const char *expected_content, size_t expected_length) { |
| 4073 | static const char *const hooks_path[] = {"hooks"}; |
| 4074 | #ifdef CBM_JSON_LIKE_ENABLE_TEST_API |
| 4075 | if (cbm_hook_json_prewrite_test_hook) { |
| 4076 | cbm_hook_json_prewrite_test_hook(settings_path, cbm_hook_json_prewrite_test_context); |
| 4077 | } |
| 4078 | #endif |
| 4079 | if (yyjson_mut_arr_size(event_arr) == 0U) { |
| 4080 | return cbm_json_like_remove_entry_if_unchanged(settings_path, hooks_path, 1U, hook_event, |
| 4081 | expected_content, expected_length) == 0 |
| 4082 | ? CLI_OK |
| 4083 | : CLI_ERR; |
| 4084 | } |
| 4085 | yyjson_mut_doc_set_root(doc, event_arr); |
| 4086 | char *event_json = yyjson_mut_write(doc, YYJSON_WRITE_PRETTY, NULL); |
| 4087 | if (!event_json) { |
| 4088 | return CLI_ERR; |
| 4089 | } |
| 4090 | int rc = cbm_json_like_upsert_entry_if_unchanged(settings_path, hooks_path, 1U, hook_event, |
| 4091 | event_json, expected_content, expected_length); |
| 4092 | free(event_json); |
| 4093 | return rc == 0 ? CLI_OK : CLI_ERR; |
| 4094 | } |
| 4095 | |
| 4096 | static int upsert_hooks_json(hooks_upsert_args_t args) { |
| 4097 | const char *settings_path = args.settings_path; |
no test coverage detected