| 2378 | } |
| 2379 | |
| 2380 | static int cbm_remove_json_named_mcp(const char *config_path, const char *const *object_path, |
| 2381 | size_t path_len, cbm_json_mcp_schema_t schema, |
| 2382 | const char *entry_name, const char *argument, |
| 2383 | const char *expected_binary) { |
| 2384 | if (!config_path || !object_path || !entry_name || !entry_name[0]) { |
| 2385 | return CLI_ERR; |
| 2386 | } |
| 2387 | char *document = NULL; |
| 2388 | size_t document_length = 0U; |
| 2389 | int read_result = cbm_json_like_read_document(config_path, &document, &document_length); |
| 2390 | if (read_result == 1) { |
| 2391 | free(document); |
| 2392 | return CLI_OK; |
| 2393 | } |
| 2394 | if (read_result < 0) { |
| 2395 | free(document); |
| 2396 | return CLI_ERR; |
| 2397 | } |
| 2398 | int ownership = |
| 2399 | cbm_json_mcp_snapshot_ownership(document, document_length, object_path, path_len, schema, |
| 2400 | entry_name, argument, expected_binary, NULL, NULL); |
| 2401 | if (ownership == CBM_JSON_LIKE_OBJECT_MISSING || ownership == CBM_JSON_LIKE_OBJECT_MISMATCH || |
| 2402 | ownership == CBM_JSON_MCP_OWNERSHIP_STALE) { |
| 2403 | free(document); |
| 2404 | return CLI_OK; |
| 2405 | } |
| 2406 | if (ownership != CBM_JSON_LIKE_OBJECT_MATCH) { |
| 2407 | free(document); |
| 2408 | return CLI_ERR; |
| 2409 | } |
| 2410 | int edit_result = cbm_json_like_remove_entry_if_unchanged( |
| 2411 | config_path, object_path, path_len, entry_name, document, document_length); |
| 2412 | free(document); |
| 2413 | return edit_result == 0 ? CLI_OK : CLI_ERR; |
| 2414 | } |
| 2415 | |
| 2416 | static int cbm_remove_json_mcp(const char *config_path, const char *const *object_path, |
| 2417 | size_t path_len, cbm_json_mcp_schema_t schema, |
no test coverage detected