From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 9C33C38485A8; Thu, 7 Jul 2022 23:33:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C33C38485A8 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-10137] libstdc++: Properly remove temporary directories in filesystem tests X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: debbc74f170c9e3ccbb7eaea13fb483a619a6dbf X-Git-Newrev: 5e384aff20a70270062011e958260eb3dc39aca9 Message-Id: <20220707233351.9C33C38485A8@sourceware.org> Date: Thu, 7 Jul 2022 23:33:51 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jul 2022 23:33:51 -0000 https://gcc.gnu.org/g:5e384aff20a70270062011e958260eb3dc39aca9 commit r11-10137-g5e384aff20a70270062011e958260eb3dc39aca9 Author: Jonathan Wakely Date: Thu Jun 23 14:25:49 2022 +0100 libstdc++: Properly remove temporary directories in filesystem tests 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) Diff: --- .../testsuite/27_io/filesystem/iterators/error_reporting.cc | 9 +++++++-- .../experimental/filesystem/iterators/error_reporting.cc | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/testsuite/27_io/filesystem/iterators/error_reporting.cc b/libstdc++-v3/testsuite/27_io/filesystem/iterators/error_reporting.cc index 1c8ea4c9249..a26b29f0974 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/iterators/error_reporting.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/error_reporting.cc @@ -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 diff --git a/libstdc++-v3/testsuite/experimental/filesystem/iterators/error_reporting.cc b/libstdc++-v3/testsuite/experimental/filesystem/iterators/error_reporting.cc index 806c511ebef..f005b7d5293 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/iterators/error_reporting.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/iterators/error_reporting.cc @@ -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