* [committed] libstdc++: Add more tests for filesystem::create_directory [PR101510]
@ 2021-07-20 11:59 Jonathan Wakely
2021-07-20 19:36 ` [committed] libstdc++: Fix create_directories to resolve symlinks [PR101510] Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2021-07-20 11:59 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- 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);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* [committed] libstdc++: Fix create_directories to resolve symlinks [PR101510]
2021-07-20 11:59 [committed] libstdc++: Add more tests for filesystem::create_directory [PR101510] Jonathan Wakely
@ 2021-07-20 19:36 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2021-07-20 19:36 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1662 bytes --]
On 20/07/21 12:59 +0100, Jonathan Wakely wrote:
>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.
>
It turned out this bug report wasn't actually about create_directory,
but create_directories, which does have a bug.
When filesystem__create_directories checks to see if the path already
exists and resovles to a directory, it uses filesystem::symlink_status,
which means it reports an error if the path is a symlink. It should use
filesystem::status, so that the target directory is detected, and no
error is reported.
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:
PR libstdc++/101510
* src/c++17/fs_ops.cc (fs::create_directories): Use status
instead of symlink_status.
* src/filesystem/ops.cc (fs::create_directories): Likewise.
* testsuite/27_io/filesystem/operations/create_directories.cc:
* testsuite/27_io/filesystem/operations/create_directory.cc: Do
not test with symlinks on Windows.
* testsuite/experimental/filesystem/operations/create_directories.cc:
* testsuite/experimental/filesystem/operations/create_directory.cc:
Do not test with symlinks on Windows.
Tested powerpc64le-linux. Committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 5962 bytes --]
commit 124eaa50e0a34f5f89572c1aa812c50979da58fc
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Jul 20 18:15:48 2021
libstdc++: Fix create_directories to resolve symlinks [PR101510]
When filesystem__create_directories checks to see if the path already
exists and resovles to a directory, it uses filesystem::symlink_status,
which means it reports an error if the path is a symlink. It should use
filesystem::status, so that the target directory is detected, and no
error is reported.
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:
PR libstdc++/101510
* src/c++17/fs_ops.cc (fs::create_directories): Use status
instead of symlink_status.
* src/filesystem/ops.cc (fs::create_directories): Likewise.
* testsuite/27_io/filesystem/operations/create_directories.cc:
* testsuite/27_io/filesystem/operations/create_directory.cc: Do
not test with symlinks on Windows.
* testsuite/experimental/filesystem/operations/create_directories.cc:
* testsuite/experimental/filesystem/operations/create_directory.cc:
Do not test with symlinks on Windows.
diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc
index cec76446f06..ceaf0291d64 100644
--- a/libstdc++-v3/src/c++17/fs_ops.cc
+++ b/libstdc++-v3/src/c++17/fs_ops.cc
@@ -496,7 +496,7 @@ fs::create_directories(const path& p, error_code& ec)
return false;
}
- file_status st = symlink_status(p, ec);
+ file_status st = status(p, ec);
if (is_directory(st))
return false;
else if (ec && !status_known(st))
diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc
index c400376d224..7c5b164fb7f 100644
--- a/libstdc++-v3/src/filesystem/ops.cc
+++ b/libstdc++-v3/src/filesystem/ops.cc
@@ -426,7 +426,7 @@ fs::create_directories(const path& p, error_code& ec) noexcept
return false;
}
- file_status st = symlink_status(p, ec);
+ file_status st = status(p, ec);
if (is_directory(st))
return false;
else if (ec && !status_known(st))
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directories.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directories.cc
index 393d6a55309..304c1453afe 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directories.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directories.cc
@@ -145,10 +145,33 @@ test03()
remove_all(p);
}
+void
+test04()
+{
+#if defined(__MINGW32__) || defined(__MINGW64__)
+ // no symlinks
+#else
+ // PR libstdc++/101510
+ // create_directories reports an error if the path is a symlink to a dir
+ std::error_code ec = make_error_code(std::errc::invalid_argument);
+ const auto p = __gnu_test::nonexistent_path() / "";
+ fs::create_directories(p/"dir");
+ auto link = p/"link";
+ fs::create_directory_symlink("dir", link);
+ bool created = fs::create_directories(link, ec);
+ VERIFY( !created );
+ VERIFY( !ec );
+ created = fs::create_directories(link);
+ VERIFY( !created );
+ remove_all(p);
+#endif
+}
+
int
main()
{
test01();
test02();
test03();
+ test04();
}
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 256621481d7..afddccf5ed6 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directory.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directory.cc
@@ -70,6 +70,9 @@ test01()
VERIFY( e.path1() == f );
}
+#if defined(__MINGW32__) || defined(__MINGW64__)
+ // no symlinks
+#else
// PR libstdc++/101510 create_directory on an existing symlink to a directory
fs::create_directory(p/"dir");
auto link = p/"link";
@@ -80,6 +83,7 @@ test01()
VERIFY( !ec );
b = fs::create_directory(link);
VERIFY( !b );
+#endif
remove_all(p, ec);
}
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directories.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directories.cc
index fb264002b69..fc134ad64a3 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directories.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directories.cc
@@ -129,10 +129,33 @@ test03()
remove_all(p);
}
+void
+test04()
+{
+#if defined(__MINGW32__) || defined(__MINGW64__)
+ // no symlinks
+#else
+ // PR libstdc++/101510
+ // create_directories reports an error if the path is a symlink to a dir
+ std::error_code ec = make_error_code(std::errc::invalid_argument);
+ const auto p = __gnu_test::nonexistent_path() / "";
+ fs::create_directories(p/"dir");
+ auto link = p/"link";
+ fs::create_directory_symlink("dir", link);
+ bool created = fs::create_directories(link, ec);
+ VERIFY( !created );
+ VERIFY( !ec );
+ created = fs::create_directories(link);
+ VERIFY( !created );
+ remove_all(p);
+#endif
+}
+
int
main()
{
test01();
test02();
test03();
+ test04();
}
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc
index 39f95b61a45..8e36b762a25 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc
@@ -69,6 +69,9 @@ test01()
VERIFY( e.path1() == f );
}
+#if defined(__MINGW32__) || defined(__MINGW64__)
+ // no symlinks
+#else
// PR libstdc++/101510 create_directory on an existing symlink to a directory
fs::create_directory(p/"dir");
auto link = p/"link";
@@ -79,6 +82,7 @@ test01()
VERIFY( !ec );
b = fs::create_directory(link);
VERIFY( !b );
+#endif
remove_all(p, ec);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-07-20 19:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-20 11:59 [committed] libstdc++: Add more tests for filesystem::create_directory [PR101510] Jonathan Wakely
2021-07-20 19:36 ` [committed] libstdc++: Fix create_directories to resolve symlinks [PR101510] Jonathan Wakely
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).