Anchored cleanup: removes both scratch files and the private directory. Safe * to call more than once and on any partially-initialised scratch, so every * exit from handle_search_code can call it unconditionally. rmdir succeeding is * itself the proof nothing was left inside. */
| 9622 | * exit from handle_search_code can call it unconditionally. rmdir succeeding is |
| 9623 | * itself the proof nothing was left inside. */ |
| 9624 | static void search_scratch_close(search_scratch_t *scratch) { |
| 9625 | if (scratch->filelist) { |
| 9626 | (void)fclose(scratch->filelist); |
| 9627 | scratch->filelist = NULL; |
| 9628 | } |
| 9629 | if (scratch->pattern_path[0] != '\0') { |
| 9630 | (void)cbm_unlink(scratch->pattern_path); |
| 9631 | scratch->pattern_path[0] = '\0'; |
| 9632 | } |
| 9633 | if (scratch->filelist_path[0] != '\0') { |
| 9634 | (void)cbm_unlink(scratch->filelist_path); |
| 9635 | scratch->filelist_path[0] = '\0'; |
| 9636 | } |
| 9637 | if (scratch->dir[0] != '\0') { |
| 9638 | (void)cbm_rmdir(scratch->dir); |
| 9639 | scratch->dir[0] = '\0'; |
| 9640 | } |
| 9641 | } |
| 9642 | |
| 9643 | /* Open the scratch directory, write `pattern` to the grep -f file, and leave the |
| 9644 | * file list open for write_scoped_filelist. Returns true on success; on failure |
no test coverage detected