Skip to content

Commit 3957f39

Browse files
committed
Revert "compiletest: use std::fs::remove_dir_all now that it is available"
This reverts commit 75ed089.
1 parent e0900a1 commit 3957f39

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

Diff for: src/tools/compiletest/src/runtest.rs

+25-2
Original file line numberDiff line numberDiff line change
@@ -3265,7 +3265,7 @@ impl<'test> TestCx<'test> {
32653265

32663266
let tmpdir = cwd.join(self.output_base_name());
32673267
if tmpdir.exists() {
3268-
fs::remove_dir_all(&tmpdir).unwrap();
3268+
self.aggressive_rm_rf(&tmpdir).unwrap();
32693269
}
32703270
create_dir_all(&tmpdir).unwrap();
32713271

@@ -3404,6 +3404,29 @@ impl<'test> TestCx<'test> {
34043404
}
34053405
}
34063406

3407+
fn aggressive_rm_rf(&self, path: &Path) -> io::Result<()> {
3408+
for e in path.read_dir()? {
3409+
let entry = e?;
3410+
let path = entry.path();
3411+
if entry.file_type()?.is_dir() {
3412+
self.aggressive_rm_rf(&path)?;
3413+
} else {
3414+
// Remove readonly files as well on windows (by default we can't)
3415+
fs::remove_file(&path).or_else(|e| {
3416+
if cfg!(windows) && e.kind() == io::ErrorKind::PermissionDenied {
3417+
let mut meta = entry.metadata()?.permissions();
3418+
meta.set_readonly(false);
3419+
fs::set_permissions(&path, meta)?;
3420+
fs::remove_file(&path)
3421+
} else {
3422+
Err(e)
3423+
}
3424+
})?;
3425+
}
3426+
}
3427+
fs::remove_dir(path)
3428+
}
3429+
34073430
fn run_rmake_v2_test(&self) {
34083431
// For `run-make` V2, we need to perform 2 steps to build and run a `run-make` V2 recipe
34093432
// (`rmake.rs`) to run the actual tests. The support library is already built as a tool rust
@@ -3452,7 +3475,7 @@ impl<'test> TestCx<'test> {
34523475
// This setup intentionally diverges from legacy Makefile run-make tests.
34533476
let base_dir = self.output_base_name();
34543477
if base_dir.exists() {
3455-
fs::remove_dir_all(&base_dir).unwrap();
3478+
self.aggressive_rm_rf(&base_dir).unwrap();
34563479
}
34573480
let rmake_out_dir = base_dir.join("rmake_out");
34583481
create_dir_all(&rmake_out_dir).unwrap();

0 commit comments

Comments
 (0)