mirror of
https://git.mirrors.martin98.com/https://github.com/gulrak/filesystem
synced 2025-06-04 11:13:58 +08:00
#4: Added test code, fixed missing error_code propagation, and error handling in fs::copy and fs::remove_all.
This commit is contained in:
parent
ad83c41d1b
commit
a4303f9207
13
filesystem.h
13
filesystem.h
@ -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;
|
||||
}
|
||||
}
|
||||
if(!ec) {
|
||||
remove(p, ec);
|
||||
}
|
||||
if (ec) {
|
||||
return static_cast<uintmax_t>(-1);
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user