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. */
| 9795 | * file list open for write_scoped_filelist. Returns true on success; on failure |
| 9796 | * everything already created is removed before returning. */ |
| 9797 | static 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. */ |
| 9833 | static bool compile_path_filter(const char *filter, cbm_regex_t *re) { |
no test coverage detected