about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-08-21 19:35:14 +0200
committerGitHub <noreply@github.com>2024-08-21 19:35:14 +0200
commit33dc313625c87c8e190f8389a0bfe3fe6730f25e (patch)
tree2c83e197b34e51c4912566fa813edfe6557be872
parentade33251f1d528443d1a4f04d5ad0ae7fc278c77 (diff)
parent75ed08972703798888fceff12b3217408ca6a4b5 (diff)
downloadrust-33dc313625c87c8e190f8389a0bfe3fe6730f25e.tar.gz
rust-33dc313625c87c8e190f8389a0bfe3fe6730f25e.zip
Rollup merge of #129302 - jieyouxu:compiletest-RAGEY, r=compiler-errors
compiletest: use `std::fs::remove_dir_all` now that it is available

It turns out `aggressive_rm_rf` is not sufficiently aggressive (RAGEY) on Windows and obviously handles Windows symlinks incorrectly. Instead of rolling our own version, let's use `std::fs::remove_dir_all` now that it's available (well, it's been available for a good while, but probably wasn't available when this helper was written).

cc #129187 since basically this is failing due to similar problems.

Blocker for #128562.
Fixes #129155.
Fixes #126334.
-rw-r--r--src/tools/compiletest/src/runtest.rs27
1 files changed, 2 insertions, 25 deletions
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index eca21e55989..6d45040345a 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -3265,7 +3265,7 @@ impl<'test> TestCx<'test> {
 
         let tmpdir = cwd.join(self.output_base_name());
         if tmpdir.exists() {
-            self.aggressive_rm_rf(&tmpdir).unwrap();
+            fs::remove_dir_all(&tmpdir).unwrap();
         }
         create_dir_all(&tmpdir).unwrap();
 
@@ -3404,29 +3404,6 @@ impl<'test> TestCx<'test> {
         }
     }
 
-    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)
-    }
-
     fn run_rmake_v2_test(&self) {
         // For `run-make` V2, we need to perform 2 steps to build and run a `run-make` V2 recipe
         // (`rmake.rs`) to run the actual tests. The support library is already built as a tool rust
@@ -3475,7 +3452,7 @@ impl<'test> TestCx<'test> {
         // This setup intentionally diverges from legacy Makefile run-make tests.
         let base_dir = self.output_base_name();
         if base_dir.exists() {
-            self.aggressive_rm_rf(&base_dir).unwrap();
+            fs::remove_dir_all(&base_dir).unwrap();
         }
         let rmake_out_dir = base_dir.join("rmake_out");
         create_dir_all(&rmake_out_dir).unwrap();