Skip to content

Commit c287f6e

Browse files
committed
compiletest: Avoid race condition in file deletion
1 parent e92ffc3 commit c287f6e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,12 +2766,11 @@ impl<'test> TestCx<'test> {
27662766
.map_err(|err| format!("failed to load expected output from `{}`: {}", path, err))
27672767
}
27682768

2769+
/// Attempts to delete a file, succeeding if the file does not exist.
27692770
fn delete_file(&self, file: &Utf8Path) {
2770-
if !file.exists() {
2771-
// Deleting a nonexistent file would error.
2772-
return;
2773-
}
2774-
if let Err(e) = fs::remove_file(file.as_std_path()) {
2771+
if let Err(e) = fs::remove_file(file.as_std_path())
2772+
&& e.kind() != io::ErrorKind::NotFound
2773+
{
27752774
self.fatal(&format!("failed to delete `{}`: {}", file, e,));
27762775
}
27772776
}

0 commit comments

Comments
 (0)