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

Function search_scratch_open

src/mcp/mcp.c:9646–9679  ·  view source on GitHub ↗

Open the scratch directory, write `pattern` to the grep -f file, and leave the * file list open for write_scoped_filelist. Returns true on success; on failure * everything already created is removed before returning. */

Source from the content-addressed store, hash-verified

9644 * file list open for write_scoped_filelist. Returns true on success; on failure
9645 * everything already created is removed before returning. */
9646static bool search_scratch_open(search_scratch_t *scratch, const char *pattern) {
9647 scratch->dir[0] = '\0';
9648 scratch->pattern_path[0] = '\0';
9649 scratch->filelist_path[0] = '\0';
9650 scratch->filelist = NULL;
9651
9652 int written =
9653 snprintf(scratch->dir, sizeof(scratch->dir), "%s/cbm-search-XXXXXX", cbm_tmpdir());
9654 if (written <= 0 || (size_t)written >= sizeof(scratch->dir) || !cbm_mkdtemp(scratch->dir)) {
9655 scratch->dir[0] = '\0';
9656 return false;
9657 }
9658
9659 FILE *pattern_file = search_scratch_file(scratch->dir, "pat", scratch->pattern_path,
9660 sizeof(scratch->pattern_path));
9661 if (!pattern_file) {
9662 search_scratch_close(scratch);
9663 return false;
9664 }
9665 bool ok = fprintf(pattern_file, "%s\n", pattern) >= 0;
9666 ok = fclose(pattern_file) == 0 && ok;
9667 if (!ok) {
9668 search_scratch_close(scratch);
9669 return false;
9670 }
9671
9672 scratch->filelist = search_scratch_file(scratch->dir, "files", scratch->filelist_path,
9673 sizeof(scratch->filelist_path));
9674 if (!scratch->filelist) {
9675 search_scratch_close(scratch);
9676 return false;
9677 }
9678 return true;
9679}
9680
9681/* Compile a path filter regex. Returns true if compiled successfully. */
9682static bool compile_path_filter(const char *filter, cbm_regex_t *re) {

Callers 1

handle_search_codeFunction · 0.85

Calls 4

cbm_tmpdirFunction · 0.85
cbm_mkdtempFunction · 0.85
search_scratch_fileFunction · 0.85
search_scratch_closeFunction · 0.85

Tested by

no test coverage detected