From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Add more tests for filesystem::create_directory [PR101510]
Date: Tue, 20 Jul 2021 12:59:04 +0100 [thread overview]
Message-ID: <YPa6iNtRm3DPojfi@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 410 bytes --]
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
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.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3724 bytes --]
commit 0c4ae4ff46b1d7633f1e06f57d348b5817b8f640
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Jul 20 12:35:37 2021
libstdc++: Add more tests for filesystem::create_directory [PR101510]
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
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<std::underlying_type_t<fs::perms>>(perm);
+ posix::mode_t mode = static_cast<std::underlying_type_t<fs::perms>>(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);
}
next reply other threads:[~2021-07-20 11:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-20 11:59 Jonathan Wakely [this message]
2021-07-20 19:36 ` [committed] libstdc++: Fix create_directories to resolve symlinks [PR101510] Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YPa6iNtRm3DPojfi@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).