mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Rollup merge of #149004 - clubby789:compiletest-delete-safe, r=jieyouxu
compiletest: Avoid race condition in file deletion Fixes rust-lang/rust#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.
This commit is contained in:
@@ -2766,12 +2766,11 @@ fn load_expected_output_from_path(&self, path: &Utf8Path) -> Result<String, Stri
|
||||
.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,));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user