From c287f6e4650dc209aff02d47927a0d0c8c6cfdc9 Mon Sep 17 00:00:00 2001 From: Jamie Hill-Daniel Date: Sun, 16 Nov 2025 20:28:56 +0000 Subject: [PATCH] compiletest: Avoid race condition in file deletion --- src/tools/compiletest/src/runtest.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 8527f7e8128f4..ddcda91c13d01 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2766,12 +2766,11 @@ impl<'test> TestCx<'test> { .map_err(|err| format!("failed to load expected output from `{}`: {}", path, err)) } + /// Attempts to delete a file, succeeding if the file does not exist. fn delete_file(&self, file: &Utf8Path) { - if !file.exists() { - // Deleting a nonexistent file would error. - return; - } - if let Err(e) = fs::remove_file(file.as_std_path()) { + if let Err(e) = fs::remove_file(file.as_std_path()) + && e.kind() != io::ErrorKind::NotFound + { self.fatal(&format!("failed to delete `{}`: {}", file, e,)); } }