diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-04-28 13:06:31 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-04-28 13:33:48 +0100 |
commit | 4e117418fb71f508c479e0144500f4da9cc92520 (patch) | |
tree | cf1ec94b493c3c0c63e162d6840f38efd65ea04a /libstdc++-v3/src | |
parent | d91cb2059fb8b5a50a2aced199e987ab2cf3b629 (diff) | |
download | gcc-4e117418fb71f508c479e0144500f4da9cc92520.zip gcc-4e117418fb71f508c479e0144500f4da9cc92520.tar.gz gcc-4e117418fb71f508c479e0144500f4da9cc92520.tar.bz2 |
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/src')
-rw-r--r-- | libstdc++-v3/src/c++17/fs_ops.cc | 8 | ||||
-rw-r--r-- | libstdc++-v3/src/filesystem/ops.cc | 8 |
2 files changed, 12 insertions, 4 deletions
diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc index 4552a73..435368f 100644 --- a/libstdc++-v3/src/c++17/fs_ops.cc +++ b/libstdc++-v3/src/c++17/fs_ops.cc @@ -408,8 +408,12 @@ fs::copy(const path& from, const path& to, copy_options options, // set an unused bit in options to disable further recursion if (!is_set(options, copy_options::recursive)) options |= static_cast<copy_options>(4096); - for (const directory_entry& x : directory_iterator(from)) - copy(x.path(), to/x.path().filename(), options, ec); + for (const directory_entry& x : directory_iterator(from, ec)) + { + copy(x.path(), to/x.path().filename(), options, ec); + if (ec) + return; + } } // _GLIBCXX_RESOLVE_LIB_DEFECTS // 2683. filesystem::copy() says "no effects" diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc index e2a2cef..98ddff5 100644 --- a/libstdc++-v3/src/filesystem/ops.cc +++ b/libstdc++-v3/src/filesystem/ops.cc @@ -350,8 +350,12 @@ fs::copy(const path& from, const path& to, copy_options options, // set an unused bit in options to disable further recursion if (!is_set(options, copy_options::recursive)) options |= static_cast<copy_options>(4096); - for (const directory_entry& x : directory_iterator(from)) - copy(x.path(), to/x.path().filename(), options, ec); + for (const directory_entry& x : directory_iterator(from, ec)) + { + copy(x.path(), to/x.path().filename(), options, ec); + if (ec) + return; + } } // _GLIBCXX_RESOLVE_LIB_DEFECTS // 2683. filesystem::copy() says "no effects" |