| 2061 | } |
| 2062 | |
| 2063 | static int cbm_remove_json_named_mcp(const char *config_path, const char *const *object_path, |
| 2064 | size_t path_len, cbm_json_mcp_schema_t schema, |
| 2065 | const char *entry_name, const char *argument, |
| 2066 | const char *expected_binary) { |
| 2067 | if (!config_path || !object_path || !entry_name || !entry_name[0]) { |
| 2068 | return CLI_ERR; |
| 2069 | } |
| 2070 | char *document = NULL; |
| 2071 | size_t document_length = 0U; |
| 2072 | int read_result = cbm_json_like_read_document(config_path, &document, &document_length); |
| 2073 | if (read_result == 1) { |
| 2074 | free(document); |
| 2075 | return CLI_OK; |
| 2076 | } |
| 2077 | if (read_result < 0) { |
| 2078 | free(document); |
| 2079 | return CLI_ERR; |
| 2080 | } |
| 2081 | int ownership = |
| 2082 | cbm_json_mcp_snapshot_ownership(document, document_length, object_path, path_len, schema, |
| 2083 | entry_name, argument, expected_binary, NULL); |
| 2084 | if (ownership == CBM_JSON_LIKE_OBJECT_MISSING || ownership == CBM_JSON_LIKE_OBJECT_MISMATCH || |
| 2085 | ownership == CBM_JSON_MCP_OWNERSHIP_STALE) { |
| 2086 | free(document); |
| 2087 | return CLI_OK; |
| 2088 | } |
| 2089 | if (ownership != CBM_JSON_LIKE_OBJECT_MATCH) { |
| 2090 | free(document); |
| 2091 | return CLI_ERR; |
| 2092 | } |
| 2093 | int edit_result = cbm_json_like_remove_entry_if_unchanged( |
| 2094 | config_path, object_path, path_len, entry_name, document, document_length); |
| 2095 | free(document); |
| 2096 | return edit_result == 0 ? CLI_OK : CLI_ERR; |
| 2097 | } |
| 2098 | |
| 2099 | static int cbm_remove_json_mcp(const char *config_path, const char *const *object_path, |
| 2100 | size_t path_len, cbm_json_mcp_schema_t schema, |
no test coverage detected