From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 952403982409; Wed, 11 Aug 2021 15:42:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 952403982409 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-8849] libstdc++: Add more tests for filesystem::create_directory [PR101510] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 546cf317558bfb178b7cadd346bb43cb963e9ce6 X-Git-Newrev: c5f17274aabe61bb0193b8b68283c1f1da5ee699 Message-Id: <20210811154248.952403982409@sourceware.org> Date: Wed, 11 Aug 2021 15:42:48 +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: Wed, 11 Aug 2021 15:42:48 -0000 https://gcc.gnu.org/g:c5f17274aabe61bb0193b8b68283c1f1da5ee699 commit r11-8849-gc5f17274aabe61bb0193b8b68283c1f1da5ee699 Author: Jonathan Wakely Date: Tue Jul 20 12:35:37 2021 +0100 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. (cherry picked from commit 0c4ae4ff46b1d7633f1e06f57d348b5817b8f640) Diff: --- libstdc++-v3/src/c++17/fs_ops.cc | 3 +-- .../filesystem/operations/create_directory.cc | 27 +++++++++++++++++++++ .../filesystem/operations/create_directory.cc | 28 ++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) 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); }