MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / jl_remove_entry

Function jl_remove_entry

src/cli/config_json_like.c:2216–2315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2214}
2215
2216static int jl_remove_entry(const char *file_path, const char *const *object_path, size_t path_len,
2217 const char *entry_key, bool enforce_expected,
2218 const char *expected_content, size_t expected_length) {
2219 if (jl_validate_arguments(file_path, object_path, path_len, entry_key) != 0) {
2220 return -1;
2221 }
2222 char *source = NULL;
2223 size_t source_length = 0;
2224 bool missing = false;
2225 jl_file_snapshot_t snapshot;
2226 if (jl_read_file(file_path, &source, &source_length, &missing, &snapshot) != 0) {
2227 return -1;
2228 }
2229 if (enforce_expected) {
2230 bool expected_missing = expected_content == NULL;
2231 bool content_matches = expected_missing
2232 ? missing
2233 : !missing && source_length == expected_length &&
2234 (expected_length == 0U ||
2235 memcmp(source, expected_content, expected_length) == 0);
2236 if (!content_matches) {
2237 free(source);
2238 return -1;
2239 }
2240 }
2241 if (missing || source_length == 0U) {
2242 free(source);
2243 return 0;
2244 }
2245
2246 size_t object_start = 0;
2247 if (jl_validate_document(source, source_length, &object_start) != 0) {
2248 free(source);
2249 return -1;
2250 }
2251 for (size_t i = 0; i < path_len; i++) {
2252 jl_object_t object;
2253 if (jl_scan_object(source, source_length, object_start, object_path[i], &object) != 0 ||
2254 object.match_count > 1U) {
2255 free(source);
2256 return -1;
2257 }
2258 if (object.match_count == 0U) {
2259 free(source);
2260 return 0;
2261 }
2262 if (source[object.match.value_start] != '{') {
2263 free(source);
2264 return -1;
2265 }
2266 object_start = object.match.value_start;
2267 }
2268
2269 jl_object_t object;
2270 if (jl_scan_object(source, source_length, object_start, entry_key, &object) != 0 ||
2271 object.match_count > 1U) {
2272 free(source);
2273 return -1;

Calls 7

jl_validate_argumentsFunction · 0.85
jl_read_fileFunction · 0.85
jl_validate_documentFunction · 0.85
jl_scan_objectFunction · 0.85
jl_apply_editsFunction · 0.85
jl_write_documentFunction · 0.85

Tested by

no test coverage detected