From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E65F43856DCF for ; Thu, 23 Jun 2022 16:21:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E65F43856DCF Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-362-N_5R63UrOA6n9-tXRswdZQ-1; Thu, 23 Jun 2022 12:21:15 -0400 X-MC-Unique: N_5R63UrOA6n9-tXRswdZQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 48C598037A9; Thu, 23 Jun 2022 16:21:15 +0000 (UTC) Received: from localhost (unknown [10.33.36.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D0152026D64; Thu, 23 Jun 2022 16:21:14 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Properly remove temporary directories in filesystem tests Date: Thu, 23 Jun 2022 17:21:14 +0100 Message-Id: <20220623162114.785979-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2022 16:21:20 -0000 Tested x86_64-linux, pushed to trunk. -- >8 -- 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. --- .../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 -- 2.36.1