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