summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/filesystem
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-04-28 13:06:31 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-04-28 13:33:48 +0100
commit4e117418fb71f508c479e0144500f4da9cc92520 (patch)
treecf1ec94b493c3c0c63e162d6840f38efd65ea04a /libstdc++-v3/testsuite/27_io/filesystem
parentd91cb2059fb8b5a50a2aced199e987ab2cf3b629 (diff)
libstdc++: Fix error reporting in filesystem::copy [PR99290]
The recursive calls to filesystem::copy should stop if any of them reports an error. libstdc++-v3/ChangeLog: PR libstdc++/99290 * src/c++17/fs_ops.cc (fs::copy): Pass error_code to directory_iterator constructor, and check on each iteration. * src/filesystem/ops.cc (fs::copy): Likewise. * testsuite/27_io/filesystem/operations/copy.cc: Check for errors during recursion. * testsuite/experimental/filesystem/operations/copy.cc: Likewise.
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/filesystem')
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/copy.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/copy.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/copy.cc
index b85628cdf30..b936e04493b 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/copy.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/copy.cc
@@ -193,6 +193,34 @@ test05()
VERIFY( !ec ); // Previous value should be cleared (LWG 2683)
}
+void
+test_pr99290()
+{
+ auto dir = __gnu_test::nonexistent_path();
+ auto source = dir/"source";
+ auto dest = dir/"dest";
+ create_directories(source/"emptydir");
+ create_directories(dest/"emptydir");
+ std::ofstream{source/"file"} << 'a';
+ std::ofstream{dest/"file"} << 'b';
+ // PR libstdc++/99290
+ // std::filesystem::copy does not always report errors for recursion
+ std::error_code ec;
+ copy(source, dest, ec);
+ VERIFY( ec == std::errc::file_exists );
+
+#if __cpp_exceptions
+ try {
+ copy(source, dest);
+ VERIFY( false );
+ } catch (const fs::filesystem_error& e) {
+ VERIFY( e.code() == std::errc::file_exists );
+ }
+#endif
+
+ remove_all(dir);
+}
+
int
main()
{
@@ -201,4 +229,5 @@ main()
test03();
test04();
test05();
+ test_pr99290();
}