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. */
| 9773 | * exit from handle_search_code can call it unconditionally. rmdir succeeding is |
| 9774 | * itself the proof nothing was left inside. */ |
| 9775 | static void search_scratch_close(search_scratch_t *scratch) { |
| 9776 | if (scratch->filelist) { |
| 9777 | (void)fclose(scratch->filelist); |
| 9778 | scratch->filelist = NULL; |
| 9779 | } |
| 9780 | if (scratch->pattern_path[0] != '\0') { |
| 9781 | (void)cbm_unlink(scratch->pattern_path); |
| 9782 | scratch->pattern_path[0] = '\0'; |
| 9783 | } |
| 9784 | if (scratch->filelist_path[0] != '\0') { |
| 9785 | (void)cbm_unlink(scratch->filelist_path); |
| 9786 | scratch->filelist_path[0] = '\0'; |
| 9787 | } |
| 9788 | if (scratch->dir[0] != '\0') { |
| 9789 | (void)cbm_rmdir(scratch->dir); |
| 9790 | scratch->dir[0] = '\0'; |
| 9791 | } |
| 9792 | } |
| 9793 | |
| 9794 | /* Open the scratch directory, write `pattern` to the grep -f file, and leave the |
| 9795 | * file list open for write_scoped_filelist. Returns true on success; on failure |
no test coverage detected