libstdc++: Properly remove temporary directories in filesystem tests
authorJonathan Wakely <jwakely@redhat.com>
Thu, 23 Jun 2022 13:25:49 +0000 (14:25 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 7 Jul 2022 20:32:42 +0000 (21:32 +0100)
Although these tests use filesystem::remove_all to clean up, that fails
because it uses recursive_directory_iterator which is intentionally
bodged by the custom readdir defined in the test.

Just use POSIX rmdir to clean up. We don't need to use _rmdir or _wrmdir
for Windows, because we'll never reach test02() on targets where the
custom readdir doesn't interpose the one from libc.

libstdc++-v3/ChangeLog:

* testsuite/27_io/filesystem/iterators/error_reporting.cc: Use
rmdir to remove directories.
* testsuite/experimental/filesystem/iterators/error_reporting.cc:
Likewise.

(cherry picked from commit 7c1c7e120cca183671b11ba68a6350c8800823c0)

libstdc++-v3/testsuite/27_io/filesystem/iterators/error_reporting.cc
libstdc++-v3/testsuite/experimental/filesystem/iterators/error_reporting.cc

index 1c8ea4c..a26b29f 100644 (file)
@@ -107,7 +107,7 @@ void
 test02()
 {
   namespace fs = std::filesystem;
-  auto dir = __gnu_test::nonexistent_path();
+  const auto dir = __gnu_test::nonexistent_path();
   fs::create_directories(dir/"subdir");
 
   std::error_code ec;
@@ -137,7 +137,12 @@ test02()
   }
 #endif
 
-  fs::remove_all(dir, ec);
+  // Cannot use fs::remove_all here because that uses
+  // recursive_directory_iterator which would use the fake readdir above.
+#ifndef _GLIBCXX_FILESYSTEM_IS_WINDOWS
+  ::rmdir((dir/"subdir").c_str());
+  ::rmdir(dir.c_str());
+#endif
 }
 
 int
index 806c511..f005b7d 100644 (file)
@@ -99,7 +99,7 @@ void
 test02()
 {
   namespace fs = std::experimental::filesystem;
-  auto dir = __gnu_test::nonexistent_path();
+  const auto dir = __gnu_test::nonexistent_path();
   fs::create_directories(dir/"subdir");
 
   std::error_code ec;
@@ -129,7 +129,12 @@ test02()
   }
 #endif
 
-  fs::remove_all(dir, ec);
+  // Cannot use fs::remove_all here because that depends on
+  // recursive_directory_iterator which would use the fake readdir above.
+#ifndef _GLIBCXX_FILESYSTEM_IS_WINDOWS
+  ::rmdir((dir/"subdir").c_str());
+  ::rmdir(dir.c_str());
+#endif
 }
 
 int