#4: Added test code, fixed missing error_code propagation, and error handling in fs::copy and fs::remove_all.

This commit is contained in:
Steffen Schuemann 2019-01-02 19:59:27 +01:00
parent ad83c41d1b
commit a4303f9207
2 changed files with 13 additions and 5 deletions

View File

@ -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 {
@ -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;
@ -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) {
@ -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);
}

View File

@ -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;
@ -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());
}