From patchwork Tue Jul 20 11:59:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1507485 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=XwQunMNv; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GTchV5gvSz9sWl for ; Tue, 20 Jul 2021 21:59:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4B43F398CC15 for ; Tue, 20 Jul 2021 11:59:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B43F398CC15 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1626782375; bh=6Sd3woxluDV46WQ59275EvtU69Q7T6it3MFSifL0qQE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=XwQunMNvYLmbuSuqXDaVvmLSHnAQH6DDRJAE2s/gVritGLMQTCCgoOPDzBDSVWgaA UMlm67m3km7p6QGpA39cUswuCN6Rks8VhQgpM1TuBu5ovboueeKCTig/WM1G4ZXBXg +PHR9DWZTWD3PIQYuzC+d7FPBbsy8G4u2M+2VC4s= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id DD77B3861C70 for ; Tue, 20 Jul 2021 11:59:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DD77B3861C70 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-374-6zbeQHMMNpejINdNS7gMYQ-1; Tue, 20 Jul 2021 07:59:06 -0400 X-MC-Unique: 6zbeQHMMNpejINdNS7gMYQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CDCA0100C666; Tue, 20 Jul 2021 11:59:05 +0000 (UTC) Received: from localhost (unknown [10.33.36.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 725455D6CF; Tue, 20 Jul 2021 11:59:05 +0000 (UTC) Date: Tue, 20 Jul 2021 12:59:04 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add more tests for filesystem::create_directory [PR101510] Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-14.5 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, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: PR libstdc++/101510 * src/c++17/fs_ops.cc (create_dir): Adjust whitespace. * testsuite/27_io/filesystem/operations/create_directory.cc: Test creating directory with name of existing symlink to directory. * testsuite/experimental/filesystem/operations/create_directory.cc: Likewise. Tested x86_64-linux. Committed to trunk. commit 0c4ae4ff46b1d7633f1e06f57d348b5817b8f640 Author: Jonathan Wakely Date: Tue Jul 20 12:35:37 2021 libstdc++: Add more tests for filesystem::create_directory [PR101510] Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: PR libstdc++/101510 * src/c++17/fs_ops.cc (create_dir): Adjust whitespace. * testsuite/27_io/filesystem/operations/create_directory.cc: Test creating directory with name of existing symlink to directory. * testsuite/experimental/filesystem/operations/create_directory.cc: Likewise. diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc index 66207ae5e44..cec76446f06 100644 --- a/libstdc++-v3/src/c++17/fs_ops.cc +++ b/libstdc++-v3/src/c++17/fs_ops.cc @@ -577,8 +577,7 @@ namespace { bool created = false; #ifdef _GLIBCXX_HAVE_SYS_STAT_H - posix::mode_t mode - = static_cast>(perm); + posix::mode_t mode = static_cast>(perm); if (posix::mkdir(p.c_str(), mode)) { const int err = errno; diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directory.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directory.cc index a0e50471275..256621481d7 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directory.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directory.cc @@ -54,6 +54,33 @@ test01() b = create_directory(p); VERIFY( !b ); + auto f = p/"file"; + std::ofstream{f} << "create file"; + b = create_directory(f, ec); + VERIFY( ec == std::errc::file_exists ); + VERIFY( !b ); + try + { + create_directory(f); + VERIFY( false ); + } + catch (const fs::filesystem_error& e) + { + VERIFY( e.code() == std::errc::file_exists ); + VERIFY( e.path1() == f ); + } + + // PR libstdc++/101510 create_directory on an existing symlink to a directory + fs::create_directory(p/"dir"); + auto link = p/"link"; + fs::create_directory_symlink("dir", link); + ec = bad_ec; + b = fs::create_directory(link, ec); + VERIFY( !b ); + VERIFY( !ec ); + b = fs::create_directory(link); + VERIFY( !b ); + remove_all(p, ec); } diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc index ee2a74b8803..39f95b61a45 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc @@ -46,12 +46,40 @@ test01() VERIFY( exists(p) ); // Test existing path (libstdc++/71036). + ec = make_error_code(std::errc::invalid_argument); b = create_directory(p, ec); VERIFY( !ec ); VERIFY( !b ); b = create_directory(p); VERIFY( !b ); + auto f = p/"file"; + std::ofstream{f} << "create file"; + b = create_directory(f, ec); + VERIFY( ec == std::errc::file_exists ); + VERIFY( !b ); + try + { + create_directory(f); + VERIFY( false ); + } + catch (const fs::filesystem_error& e) + { + VERIFY( e.code() == std::errc::file_exists ); + VERIFY( e.path1() == f ); + } + + // PR libstdc++/101510 create_directory on an existing symlink to a directory + fs::create_directory(p/"dir"); + auto link = p/"link"; + fs::create_directory_symlink("dir", link); + ec = make_error_code(std::errc::invalid_argument); + b = fs::create_directory(link, ec); + VERIFY( !b ); + VERIFY( !ec ); + b = fs::create_directory(link); + VERIFY( !b ); + remove_all(p, ec); }