Skip to content

Commit 02165f9

Browse files
authored
Unrolled build for #149004
Rollup merge of #149004 - clubby789:compiletest-delete-safe, r=jieyouxu compiletest: Avoid race condition in file deletion Fixes #149003 There is a TOCTOU when multiple threads attempt to delete the same file. Instead of pre-checking if the file exists, we can simply ignore `NotFound` errors.
2 parents 89fe961 + c287f6e commit 02165f9

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)