| 4232 | const char *match_command_exact; |
| 4233 | } hooks_remove_args_t; |
| 4234 | static int remove_hooks_json(hooks_remove_args_t args) { |
| 4235 | const char *settings_path = args.settings_path; |
| 4236 | const char *hook_event = args.hook_event; |
| 4237 | const char *matcher_str = args.matcher_str; |
| 4238 | const char *const *old_matchers = args.old_matchers; |
| 4239 | if (!settings_path || !hook_event || !args.match_command_exact) { |
| 4240 | return CLI_ERR; |
| 4241 | } |
| 4242 | |
| 4243 | char *expected_content = NULL; |
| 4244 | size_t expected_length = 0U; |
| 4245 | int read_result = |
| 4246 | cbm_json_like_read_document(settings_path, &expected_content, &expected_length); |
| 4247 | if (read_result < 0) { |
| 4248 | return CLI_ERR; |
| 4249 | } |
| 4250 | if (read_result == 1) { |
| 4251 | return CLI_OK; |
| 4252 | } |
| 4253 | |
| 4254 | int rc = CLI_ERR; |
| 4255 | yyjson_read_flag flags = YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS; |
| 4256 | yyjson_doc *doc = yyjson_read(expected_content, expected_length, flags); |
| 4257 | if (!doc || !yyjson_is_obj(yyjson_doc_get_root(doc))) { |
| 4258 | yyjson_doc_free(doc); |
| 4259 | free(expected_content); |
| 4260 | return CLI_ERR; |
| 4261 | } |
| 4262 | yyjson_mut_doc *mdoc = yyjson_mut_doc_new(NULL); |
| 4263 | if (!mdoc) { |
| 4264 | yyjson_doc_free(doc); |
| 4265 | free(expected_content); |
| 4266 | return CLI_ERR; |
| 4267 | } |
| 4268 | yyjson_mut_val *root = yyjson_val_mut_copy(mdoc, yyjson_doc_get_root(doc)); |
| 4269 | yyjson_doc_free(doc); |
| 4270 | if (!root) { |
| 4271 | yyjson_mut_doc_free(mdoc); |
| 4272 | free(expected_content); |
| 4273 | return CLI_ERR; |
| 4274 | } |
| 4275 | yyjson_mut_doc_set_root(mdoc, root); |
| 4276 | |
| 4277 | yyjson_mut_val *hooks = yyjson_mut_obj_get(root, "hooks"); |
| 4278 | if (!hooks) { |
| 4279 | yyjson_mut_doc_free(mdoc); |
| 4280 | free(expected_content); |
| 4281 | return CLI_OK; |
| 4282 | } |
| 4283 | if (!yyjson_mut_is_obj(hooks)) { |
| 4284 | yyjson_mut_doc_free(mdoc); |
| 4285 | free(expected_content); |
| 4286 | return CLI_ERR; |
| 4287 | } |
| 4288 | |
| 4289 | yyjson_mut_val *event_arr = yyjson_mut_obj_get(hooks, hook_event); |
| 4290 | if (!event_arr) { |
| 4291 | yyjson_mut_doc_free(mdoc); |
no test coverage detected