Skip to content

Commit 8cddfcb

Browse files
committed
#4: Removed range-based for-loops with fs::directory_iterator in error_code versions of fs::copy and fs::remove_all as they are compatible with "noexcet".
1 parent 974c9bd commit 8cddfcb

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

filesystem.h

+11-6
Original file line numberDiff line numberDiff line change
@@ -2812,8 +2812,10 @@ inline void copy(const path& from, const path& to, copy_options options, std::er
28122812
return;
28132813
}
28142814
}
2815-
for (const directory_entry& x : directory_iterator(from, ec)) {
2816-
copy(x.path(), to / x.path().filename(), options | static_cast<copy_options>(0x8000), ec);
2815+
for (auto iter = directory_iterator(from, ec); iter != directory_iterator(); iter.increment(ec)) {
2816+
if(!ec) {
2817+
copy(iter->path(), to / iter->path().filename(), options | static_cast<copy_options>(0x8000), ec);
2818+
}
28172819
if(ec) {
28182820
return;
28192821
}
@@ -3688,15 +3690,18 @@ inline uintmax_t remove_all(const path& p, std::error_code& ec) noexcept
36883690
ec = detail::make_error_code(detail::portable_error::not_supported);
36893691
return static_cast<uintmax_t>(-1);
36903692
}
3691-
for (const directory_entry& de : directory_iterator(p, ec)) {
3692-
if (!de.is_symlink() && de.is_directory()) {
3693-
count += remove_all(de.path(), ec);
3693+
for (auto iter = directory_iterator(p, ec); iter != directory_iterator(); iter.increment(ec)) {
3694+
if(ec) {
3695+
break;
3696+
}
3697+
if (!iter->is_symlink() && iter->is_directory()) {
3698+
count += remove_all(iter->path(), ec);
36943699
if (ec) {
36953700
return static_cast<uintmax_t>(-1);
36963701
}
36973702
}
36983703
else {
3699-
remove(de.path(), ec);
3704+
remove(iter->path(), ec);
37003705
if (ec) {
37013706
return static_cast<uintmax_t>(-1);
37023707
}

0 commit comments

Comments
 (0)