mirror of
https://git.mirrors.martin98.com/https://github.com/gulrak/filesystem
synced 2025-06-04 11:13:58 +08:00
Fix for remove_all handling when calling for non-existent or regular file. (#6)
This commit is contained in:
parent
71d05aa49d
commit
1349d3d5a5
10
README.md
10
README.md
@ -345,6 +345,16 @@ to the expected behavior.
|
||||
|
||||
## Release Notes
|
||||
|
||||
### v1.0.8 (wip)
|
||||
|
||||
* Bugfix for ([#6](https://github.com/gulrak/filesystem/issues/6)), where
|
||||
`ghc::filesystem::remove()` and `ghc::filesystem::remove_all()` both are
|
||||
now able to remove a single file and both will not raise an error if the
|
||||
path doesn't exist.
|
||||
* Merged pull request ([#7](https://github.com/gulrak/filesystem/pull/7)),
|
||||
a typo leading to setting error code instead of comparing it in
|
||||
`ghc::filesystem::remove()` under Windows.
|
||||
|
||||
### [v1.0.6](https://github.com/gulrak/filesystem/releases/tag/v1.0.6)
|
||||
|
||||
* Bugfix for ([#4](https://github.com/gulrak/filesystem/issues/4)), missing error_code
|
||||
|
@ -3660,7 +3660,6 @@ inline bool remove(const path& p, std::error_code& ec) noexcept
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
if (::remove(p.c_str()) == -1) {
|
||||
auto error = errno;
|
||||
if (error == ENOENT) {
|
||||
@ -3690,6 +3689,9 @@ 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);
|
||||
}
|
||||
std::error_code tec;
|
||||
auto fs = status(p, tec);
|
||||
if(exists(fs) && is_directory(fs)) {
|
||||
for (auto iter = directory_iterator(p, ec); iter != directory_iterator(); iter.increment(ec)) {
|
||||
if(ec) {
|
||||
break;
|
||||
@ -3708,6 +3710,7 @@ inline uintmax_t remove_all(const path& p, std::error_code& ec) noexcept
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!ec) {
|
||||
remove(p, ec);
|
||||
}
|
||||
|
@ -1984,6 +1984,7 @@ TEST_CASE("30.10.15.30 remove", "[filesystem][operations][fs.op.remove]")
|
||||
generateFile("foo");
|
||||
CHECK(fs::remove("foo"));
|
||||
CHECK(!fs::exists("foo"));
|
||||
CHECK(!fs::remove("foo"));
|
||||
generateFile("foo");
|
||||
CHECK(fs::remove("foo", ec));
|
||||
CHECK(!fs::exists("foo"));
|
||||
@ -2004,13 +2005,17 @@ TEST_CASE("30.10.15.31 remove_all", "[filesystem][operations][fs.op.remove_all]"
|
||||
{
|
||||
TemporaryDirectory t(TempOpt::change_path);
|
||||
std::error_code ec;
|
||||
generateFile("foo");
|
||||
CHECK(fs::remove_all("foo", ec) == 1);
|
||||
CHECK(!ec);
|
||||
ec.clear();
|
||||
CHECK(fs::directory_iterator(t.path()) == fs::directory_iterator());
|
||||
fs::create_directories("dir1/dir1a");
|
||||
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(!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