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

Function search_scratch_open

src/mcp/mcp.c:9797–9830  ·  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

9795 * file list open for write_scoped_filelist. Returns true on success; on failure
9796 * everything already created is removed before returning. */
9797static bool search_scratch_open(search_scratch_t *scratch, const char *pattern) {
9798 scratch->dir[0] = '\0';
9799 scratch->pattern_path[0] = '\0';
9800 scratch->filelist_path[0] = '\0';
9801 scratch->filelist = NULL;
9802
9803 int written =
9804 snprintf(scratch->dir, sizeof(scratch->dir), "%s/cbm-search-XXXXXX", cbm_tmpdir());
9805 if (written <= 0 || (size_t)written >= sizeof(scratch->dir) || !cbm_mkdtemp(scratch->dir)) {
9806 scratch->dir[0] = '\0';
9807 return false;
9808 }
9809
9810 FILE *pattern_file = search_scratch_file(scratch->dir, "pat", scratch->pattern_path,
9811 sizeof(scratch->pattern_path));
9812 if (!pattern_file) {
9813 search_scratch_close(scratch);
9814 return false;
9815 }
9816 bool ok = fprintf(pattern_file, "%s\n", pattern) >= 0;
9817 ok = fclose(pattern_file) == 0 && ok;
9818 if (!ok) {
9819 search_scratch_close(scratch);
9820 return false;
9821 }
9822
9823 scratch->filelist = search_scratch_file(scratch->dir, "files", scratch->filelist_path,
9824 sizeof(scratch->filelist_path));
9825 if (!scratch->filelist) {
9826 search_scratch_close(scratch);
9827 return false;
9828 }
9829 return true;
9830}
9831
9832/* Compile a path filter regex. Returns true if compiled successfully. */
9833static 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