| 1990 | } |
| 1991 | |
| 1992 | static int cbm_remove_json_named_mcp(const char *config_path, const char *const *object_path, |
| 1993 | size_t path_len, cbm_json_mcp_schema_t schema, |
| 1994 | const char *entry_name, const char *argument, |
| 1995 | const char *expected_binary) { |
| 1996 | if (!config_path || !object_path || !entry_name || !entry_name[0]) { |
| 1997 | return CLI_ERR; |
| 1998 | } |
| 1999 | char *document = NULL; |
| 2000 | size_t document_length = 0U; |
| 2001 | int read_result = cbm_json_like_read_document(config_path, &document, &document_length); |
| 2002 | if (read_result == 1) { |
| 2003 | free(document); |
| 2004 | return CLI_OK; |
| 2005 | } |
| 2006 | if (read_result < 0) { |
| 2007 | free(document); |
| 2008 | return CLI_ERR; |
| 2009 | } |
| 2010 | int ownership = |
| 2011 | cbm_json_mcp_snapshot_ownership(document, document_length, object_path, path_len, schema, |
| 2012 | entry_name, argument, expected_binary, NULL); |
| 2013 | if (ownership == CBM_JSON_LIKE_OBJECT_MISSING || ownership == CBM_JSON_LIKE_OBJECT_MISMATCH || |
| 2014 | ownership == CBM_JSON_MCP_OWNERSHIP_STALE) { |
| 2015 | free(document); |
| 2016 | return CLI_OK; |
| 2017 | } |
| 2018 | if (ownership != CBM_JSON_LIKE_OBJECT_MATCH) { |
| 2019 | free(document); |
| 2020 | return CLI_ERR; |
| 2021 | } |
| 2022 | int edit_result = cbm_json_like_remove_entry_if_unchanged( |
| 2023 | config_path, object_path, path_len, entry_name, document, document_length); |
| 2024 | free(document); |
| 2025 | return edit_result == 0 ? CLI_OK : CLI_ERR; |
| 2026 | } |
| 2027 | |
| 2028 | static int cbm_remove_json_mcp(const char *config_path, const char *const *object_path, |
| 2029 | size_t path_len, cbm_json_mcp_schema_t schema, |
no test coverage detected