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

Function search_root_fixture_create

tests/test_mcp.c:24300–24344  ·  view source on GitHub ↗

Layout (every line that matters carries ROOTCHECK_NEEDLE): * /main.c ordinary file, Variable INSIDE_SYMBOL * /inner/same.c ordinary file, reached via the links * /alias -> inner directory link that stays inside * /mirror.c -> inner/same.c file link that stays inside * /link.c -> /far.c file

Source from the content-addressed store, hash-verified

24298 * <outside>/dir/deep.c raw hit through the directory link
24299 * <outside>/dir/sym.c graph hit (Variable FAR_DIR_SYMBOL) */
24300static bool search_root_fixture_create(search_root_fixture_t *fx) {
24301 snprintf(fx->root, sizeof(fx->root), "%s/cbm_srch_root_XXXXXX", cbm_tmpdir());
24302 snprintf(fx->outside, sizeof(fx->outside), "%s/cbm_srch_outside_XXXXXX", cbm_tmpdir());
24303 if (!cbm_mkdtemp(fx->root) || !cbm_mkdtemp(fx->outside)) {
24304 return false;
24305 }
24306 char path[CBM_SZ_1K];
24307 char target[CBM_SZ_1K];
24308 snprintf(path, sizeof(path), "%s/main.c", fx->root);
24309 if (th_write_file(path, "int ROOTCHECK_NEEDLE_INSIDE = 1;\n") != 0) {
24310 return false;
24311 }
24312 snprintf(path, sizeof(path), "%s/inner/same.c", fx->root);
24313 if (th_write_file(path, "int ROOTCHECK_NEEDLE_INNER = 4;\n") != 0) {
24314 return false;
24315 }
24316 snprintf(path, sizeof(path), "%s/alias", fx->root);
24317 if (symlink("inner", path) != 0) {
24318 return false;
24319 }
24320 snprintf(path, sizeof(path), "%s/mirror.c", fx->root);
24321 if (symlink("inner/same.c", path) != 0) {
24322 return false;
24323 }
24324 snprintf(path, sizeof(path), "%s/far.c", fx->outside);
24325 if (th_write_file(path, "int ROOTCHECK_NEEDLE_FAR_FILE = 2;\n") != 0) {
24326 return false;
24327 }
24328 snprintf(path, sizeof(path), "%s/dir/deep.c", fx->outside);
24329 if (th_write_file(path, "int ROOTCHECK_NEEDLE_FAR_DIR = 3;\n") != 0) {
24330 return false;
24331 }
24332 snprintf(path, sizeof(path), "%s/dir/sym.c", fx->outside);
24333 if (th_write_file(path, "int ROOTCHECK_NEEDLE_FAR_SYM = 5;\n") != 0) {
24334 return false;
24335 }
24336 snprintf(target, sizeof(target), "%s/far.c", fx->outside);
24337 snprintf(path, sizeof(path), "%s/link.c", fx->root);
24338 if (symlink(target, path) != 0) {
24339 return false;
24340 }
24341 snprintf(target, sizeof(target), "%s/dir", fx->outside);
24342 snprintf(path, sizeof(path), "%s/lib", fx->root);
24343 return symlink(target, path) == 0;
24344}
24345
24346static void search_root_fixture_destroy(search_root_fixture_t *fx) {
24347 /* Unlink the links first so the tree removal never descends through one. */

Callers 1

test_mcp.cFile · 0.85

Calls 3

cbm_tmpdirFunction · 0.85
cbm_mkdtempFunction · 0.85
th_write_fileFunction · 0.85

Tested by

no test coverage detected