| 4155 | const char *match_command_exact; |
| 4156 | } hooks_remove_args_t; |
| 4157 | static int remove_hooks_json(hooks_remove_args_t args) { |
| 4158 | const char *settings_path = args.settings_path; |
| 4159 | const char *hook_event = args.hook_event; |
| 4160 | const char *matcher_str = args.matcher_str; |
| 4161 | const char *const *old_matchers = args.old_matchers; |
| 4162 | if (!settings_path || !hook_event || !args.match_command_exact) { |
| 4163 | return CLI_ERR; |
| 4164 | } |
| 4165 | |
| 4166 | char *expected_content = NULL; |
| 4167 | size_t expected_length = 0U; |
| 4168 | int read_result = |
| 4169 | cbm_json_like_read_document(settings_path, &expected_content, &expected_length); |
| 4170 | if (read_result < 0) { |
| 4171 | return CLI_ERR; |
| 4172 | } |
| 4173 | if (read_result == 1) { |
| 4174 | return CLI_OK; |
| 4175 | } |
| 4176 | |
| 4177 | int rc = CLI_ERR; |
| 4178 | yyjson_read_flag flags = YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS; |
| 4179 | yyjson_doc *doc = yyjson_read(expected_content, expected_length, flags); |
| 4180 | if (!doc || !yyjson_is_obj(yyjson_doc_get_root(doc))) { |
| 4181 | yyjson_doc_free(doc); |
| 4182 | free(expected_content); |
| 4183 | return CLI_ERR; |
| 4184 | } |
| 4185 | yyjson_mut_doc *mdoc = yyjson_mut_doc_new(NULL); |
| 4186 | if (!mdoc) { |
| 4187 | yyjson_doc_free(doc); |
| 4188 | free(expected_content); |
| 4189 | return CLI_ERR; |
| 4190 | } |
| 4191 | yyjson_mut_val *root = yyjson_val_mut_copy(mdoc, yyjson_doc_get_root(doc)); |
| 4192 | yyjson_doc_free(doc); |
| 4193 | if (!root) { |
| 4194 | yyjson_mut_doc_free(mdoc); |
| 4195 | free(expected_content); |
| 4196 | return CLI_ERR; |
| 4197 | } |
| 4198 | yyjson_mut_doc_set_root(mdoc, root); |
| 4199 | |
| 4200 | yyjson_mut_val *hooks = yyjson_mut_obj_get(root, "hooks"); |
| 4201 | if (!hooks) { |
| 4202 | yyjson_mut_doc_free(mdoc); |
| 4203 | free(expected_content); |
| 4204 | return CLI_OK; |
| 4205 | } |
| 4206 | if (!yyjson_mut_is_obj(hooks)) { |
| 4207 | yyjson_mut_doc_free(mdoc); |
| 4208 | free(expected_content); |
| 4209 | return CLI_ERR; |
| 4210 | } |
| 4211 | |
| 4212 | yyjson_mut_val *event_arr = yyjson_mut_obj_get(hooks, hook_event); |
| 4213 | if (!event_arr) { |
| 4214 | yyjson_mut_doc_free(mdoc); |
no test coverage detected