Skip to content

Commit

Permalink
compiletest: use recursive_remove instead of aggressive_rm_rf
Browse files Browse the repository at this point in the history
`aggressive_rm_rf` does not correctly handle distinction between
symlink-to-file vs symlink-to-dir on Windows.
  • Loading branch information
jieyouxu committed Dec 22, 2024
1 parent 1b9aee1 commit 5ee7228
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/tools/compiletest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ indexmap = "2.0.0"
miropt-test-tools = { path = "../miropt-test-tools" }
build_helper = { path = "../../build_helper" }
tracing = "0.1"
tracing-subscriber = { version = "0.3.3", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
tracing-subscriber = { version = "0.3.3", default-features = false, features = ["ansi", "env-filter", "fmt", "parking_lot", "smallvec"] }
regex = "1.0"
semver = { version = "1.0.23", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
Expand Down
23 changes: 0 additions & 23 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2809,29 +2809,6 @@ impl<'test> TestCx<'test> {
println!("init_incremental_test: incremental_dir={}", incremental_dir.display());
}
}

fn aggressive_rm_rf(&self, path: &Path) -> io::Result<()> {
for e in path.read_dir()? {
let entry = e?;
let path = entry.path();
if entry.file_type()?.is_dir() {
self.aggressive_rm_rf(&path)?;
} else {
// Remove readonly files as well on windows (by default we can't)
fs::remove_file(&path).or_else(|e| {
if cfg!(windows) && e.kind() == io::ErrorKind::PermissionDenied {
let mut meta = entry.metadata()?.permissions();
meta.set_readonly(false);
fs::set_permissions(&path, meta)?;
fs::remove_file(&path)
} else {
Err(e)
}
})?;
}
}
fs::remove_dir(path)
}
}

struct ProcArgs {
Expand Down
12 changes: 6 additions & 6 deletions src/tools/compiletest/src/runtest/run_make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::path::Path;
use std::process::{Command, Output, Stdio};
use std::{env, fs};

use build_helper::fs::{ignore_not_found, recursive_remove};

use super::{ProcRes, TestCx, disable_error_reporting};
use crate::util::{copy_dir_all, dylib_env_var};

Expand All @@ -27,9 +29,8 @@ impl TestCx<'_> {
// are hopefully going away, it seems safer to leave this perilous code
// as-is until it can all be deleted.
let tmpdir = cwd.join(self.output_base_name());
if tmpdir.exists() {
self.aggressive_rm_rf(&tmpdir).unwrap();
}
ignore_not_found(|| recursive_remove(&tmpdir)).unwrap();

fs::create_dir_all(&tmpdir).unwrap();

let host = &self.config.host;
Expand Down Expand Up @@ -218,9 +219,8 @@ impl TestCx<'_> {
//
// This setup intentionally diverges from legacy Makefile run-make tests.
let base_dir = self.output_base_dir();
if base_dir.exists() {
self.aggressive_rm_rf(&base_dir).unwrap();
}
ignore_not_found(|| recursive_remove(&base_dir)).unwrap();

let rmake_out_dir = base_dir.join("rmake_out");
fs::create_dir_all(&rmake_out_dir).unwrap();

Expand Down

0 comments on commit 5ee7228

Please sign in to comment.