Skip to content

Commit

Permalink
#4: Added test code, fixed missing error_code propagation, and error …
Browse files Browse the repository at this point in the history
…handling in fs::copy and fs::remove_all.
  • Loading branch information
gulrak committed Jan 2, 2019
1 parent ad83c41 commit a4303f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 10 additions & 5 deletions filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
#define LWG_2937_BEHAVIOUR

// ghc::filesystem version in decimal (major * 10000 + minor * 100 + patch)
#define GHC_FILESYSTEM_VERSION 10004L
#define GHC_FILESYSTEM_VERSION 10005L

namespace ghc {
namespace filesystem {
Expand Down Expand Up @@ -2812,8 +2812,11 @@ inline void copy(const path& from, const path& to, copy_options options, std::er
return;
}
}
for (const directory_entry& x : directory_iterator(from)) {
copy(x.path(), to / x.path().filename(), options | static_cast<copy_options>(0x8000));
for (const directory_entry& x : directory_iterator(from, ec)) {
copy(x.path(), to / x.path().filename(), options | static_cast<copy_options>(0x8000), ec);
if(ec) {
return;
}
}
}
return;
Expand Down Expand Up @@ -3685,7 +3688,7 @@ inline uintmax_t remove_all(const path& p, std::error_code& ec) noexcept
ec = detail::make_error_code(detail::portable_error::not_supported);
return static_cast<uintmax_t>(-1);
}
for (const directory_entry& de : directory_iterator(p)) {
for (const directory_entry& de : directory_iterator(p, ec)) {
if (!de.is_symlink() && de.is_directory()) {
count += remove_all(de.path(), ec);
if (ec) {
Expand All @@ -3700,7 +3703,9 @@ inline uintmax_t remove_all(const path& p, std::error_code& ec) noexcept
++count;
}
}
remove(p, ec);
if(!ec) {
remove(p, ec);
}
if (ec) {
return static_cast<uintmax_t>(-1);
}
Expand Down
3 changes: 3 additions & 0 deletions test/filesystem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ TEST_CASE("30.10.13 class directory_iterator", "[filesystem][directory_iterator]
CHECK(!iter->is_directory());
CHECK(iter->file_size() == 1234);
CHECK(++iter == fs::directory_iterator());
CHECK_THROWS_AS(fs::directory_iterator(t.path() / "non-existing"), fs::filesystem_error);
}
if (is_symlink_creation_supported()) {
TemporaryDirectory t;
Expand Down Expand Up @@ -2008,6 +2009,8 @@ TEST_CASE("30.10.15.31 remove_all", "[filesystem][operations][fs.op.remove_all]"
fs::create_directories("dir1/dir1b");
generateFile("dir1/dir1a/f1");
generateFile("dir1/dir1b/f2");
CHECK_NOTHROW(fs::remove_all("dir1/non-existing", ec));
CHECK(ec);
CHECK(fs::remove_all("dir1") == 5);
CHECK(fs::directory_iterator(t.path()) == fs::directory_iterator());
}
Expand Down

0 comments on commit a4303f9

Please sign in to comment.