summaryrefslogtreecommitdiffstats
path: root/libcxx
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx')
-rw-r--r--libcxx/src/experimental/filesystem/operations.cpp15
-rw-r--r--libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.remove/remove.pass.cpp16
-rw-r--r--libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.remove_all/remove_all.pass.cpp14
3 files changed, 38 insertions, 7 deletions
diff --git a/libcxx/src/experimental/filesystem/operations.cpp b/libcxx/src/experimental/filesystem/operations.cpp
index 662fa7b8626..91aee6ffbcb 100644
--- a/libcxx/src/experimental/filesystem/operations.cpp
+++ b/libcxx/src/experimental/filesystem/operations.cpp
@@ -661,8 +661,10 @@ path __read_symlink(const path& p, std::error_code *ec) {
bool __remove(const path& p, std::error_code *ec) {
if (ec) ec->clear();
+
if (::remove(p.c_str()) == -1) {
- set_or_throw(ec, "remove", p);
+ if (errno != ENOENT)
+ set_or_throw(ec, "remove", p);
return false;
}
return true;
@@ -692,13 +694,18 @@ std::uintmax_t remove_all_impl(path const & p, std::error_code& ec)
} // end namespace
std::uintmax_t __remove_all(const path& p, std::error_code *ec) {
+ if (ec) ec->clear();
+
std::error_code mec;
auto count = remove_all_impl(p, mec);
if (mec) {
- set_or_throw(mec, ec, "remove_all", p);
- return static_cast<std::uintmax_t>(-1);
+ if (mec == errc::no_such_file_or_directory) {
+ return 0;
+ } else {
+ set_or_throw(mec, ec, "remove_all", p);
+ return static_cast<std::uintmax_t>(-1);
+ }
}
- if (ec) ec->clear();
return count;
}
diff --git a/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.remove/remove.pass.cpp b/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.remove/remove.pass.cpp
index f7ce8a30e64..2fdb4ad4709 100644
--- a/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.remove/remove.pass.cpp
+++ b/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.remove/remove.pass.cpp
@@ -61,17 +61,29 @@ TEST_CASE(test_error_reporting)
const path file_in_bad_dir = env.create_file(bad_perms_dir / "file", 42);
permissions(bad_perms_dir, perms::none);
const path testCases[] = {
- "",
- env.make_env_path("dne"),
non_empty_dir,
file_in_bad_dir,
};
for (auto& p : testCases) {
std::error_code ec;
+
TEST_CHECK(!fs::remove(p, ec));
TEST_CHECK(ec);
TEST_CHECK(checkThrow(p, ec));
}
+
+ // PR#35780
+ const path testCasesNonexistant[] = {
+ "",
+ env.make_env_path("dne")
+ };
+
+ for (auto& p : testCasesNonexistant) {
+ std::error_code ec;
+
+ TEST_CHECK(!fs::remove(p, ec));
+ TEST_CHECK(!ec);
+ }
}
TEST_CASE(basic_remove_test)
diff --git a/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.remove_all/remove_all.pass.cpp b/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.remove_all/remove_all.pass.cpp
index b84c18c1da0..cc3b7152dac 100644
--- a/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.remove_all/remove_all.pass.cpp
+++ b/libcxx/test/std/experimental/filesystem/fs.op.funcs/fs.op.remove_all/remove_all.pass.cpp
@@ -64,16 +64,28 @@ TEST_CASE(test_error_reporting)
permissions(bad_perms_file, perms::none);
const path testCases[] = {
- env.make_env_path("dne"),
file_in_bad_dir
};
const auto BadRet = static_cast<std::uintmax_t>(-1);
for (auto& p : testCases) {
std::error_code ec;
+
TEST_CHECK(fs::remove_all(p, ec) == BadRet);
TEST_CHECK(ec);
TEST_CHECK(checkThrow(p, ec));
}
+
+ // PR#35780
+ const path testCasesNonexistant[] = {
+ "",
+ env.make_env_path("dne")
+ };
+ for (auto &p : testCasesNonexistant) {
+ std::error_code ec;
+
+ TEST_CHECK(fs::remove_all(p) == 0);
+ TEST_CHECK(!ec);
+ }
}
TEST_CASE(basic_remove_all_test)
OpenPOWER on IntegriCloud