| 4232 | #endif |
| 4233 | |
| 4234 | static int write_hook_event_array(const char *settings_path, const char *hook_event, |
| 4235 | yyjson_mut_doc *doc, yyjson_mut_val *event_arr, |
| 4236 | const char *expected_content, size_t expected_length) { |
| 4237 | static const char *const hooks_path[] = {"hooks"}; |
| 4238 | #ifdef CBM_JSON_LIKE_ENABLE_TEST_API |
| 4239 | if (cbm_hook_json_prewrite_test_hook) { |
| 4240 | cbm_hook_json_prewrite_test_hook(settings_path, cbm_hook_json_prewrite_test_context); |
| 4241 | } |
| 4242 | #endif |
| 4243 | if (yyjson_mut_arr_size(event_arr) == 0U) { |
| 4244 | return cbm_json_like_remove_entry_if_unchanged(settings_path, hooks_path, 1U, hook_event, |
| 4245 | expected_content, expected_length) == 0 |
| 4246 | ? CLI_OK |
| 4247 | : CLI_ERR; |
| 4248 | } |
| 4249 | yyjson_mut_doc_set_root(doc, event_arr); |
| 4250 | char *event_json = yyjson_mut_write(doc, YYJSON_WRITE_PRETTY, NULL); |
| 4251 | if (!event_json) { |
| 4252 | return CLI_ERR; |
| 4253 | } |
| 4254 | int rc = cbm_json_like_upsert_entry_if_unchanged(settings_path, hooks_path, 1U, hook_event, |
| 4255 | event_json, expected_content, expected_length); |
| 4256 | free(event_json); |
| 4257 | return rc == 0 ? CLI_OK : CLI_ERR; |
| 4258 | } |
| 4259 | |
| 4260 | static int upsert_hooks_json(hooks_upsert_args_t args) { |
| 4261 | const char *settings_path = args.settings_path; |
no test coverage detected