From 4ca07db039fbf0bf9b024e1b1645667939c1194e Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 5 Jan 2018 23:51:22 +0000 Subject: [PATCH] PR libstdc++/83626 simplify filesystem::remove and filesystem::remove_all PR libstdc++/83626 * src/filesystem/ops.cc (remove(const path&, error_code&)): Remove unnecessary symlink_status call. (remove_all(const path&, error_code&)): Use filesystem::remove. * src/filesystem/std-ops.cc: Likewise. From-SVN: r256301 --- libstdc++-v3/ChangeLog | 6 ++++++ libstdc++-v3/src/filesystem/ops.cc | 17 ++--------------- libstdc++-v3/src/filesystem/std-ops.cc | 19 +++---------------- 3 files changed, 11 insertions(+), 31 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 444c61550f8..b074111d003 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,11 @@ 2018-01-05 Jonathan Wakely + PR libstdc++/83626 + * src/filesystem/ops.cc (remove(const path&, error_code&)): Remove + unnecessary symlink_status call. + (remove_all(const path&, error_code&)): Use filesystem::remove. + * src/filesystem/std-ops.cc: Likewise. + PR libstdc++/83279 * src/filesystem/std-ops.cc (do_copy_file): Use non-null offset with sendfile. diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc index 3690fb94d63..899defea6d2 100644 --- a/libstdc++-v3/src/filesystem/ops.cc +++ b/libstdc++-v3/src/filesystem/ops.cc @@ -1017,14 +1017,6 @@ fs::remove(const path& p) bool fs::remove(const path& p, error_code& ec) noexcept { - const auto s = symlink_status(p, ec); - if (!status_known(s)) - return false; - if (s.type() == file_type::not_found) - { - ec.clear(); - return false; // Nothing to do, not an error. - } if (::remove(p.c_str()) == 0) { ec.clear(); @@ -1070,14 +1062,9 @@ fs::remove_all(const path& p, error_code& ec) noexcept return -1; } - if (::remove(p.c_str()) == 0) + if (fs::remove(p, ec)) ++count; - else if (errno != ENOENT) - { - ec.assign(errno, std::generic_category()); - return -1; - } - return count; + return ec ? -1 : count; } void diff --git a/libstdc++-v3/src/filesystem/std-ops.cc b/libstdc++-v3/src/filesystem/std-ops.cc index bed1ad1fe27..65b06f5b67b 100644 --- a/libstdc++-v3/src/filesystem/std-ops.cc +++ b/libstdc++-v3/src/filesystem/std-ops.cc @@ -1254,7 +1254,7 @@ bool fs::remove(const path& p) { error_code ec; - bool result = fs::remove(p, ec); + const bool result = fs::remove(p, ec); if (ec) _GLIBCXX_THROW_OR_ABORT(filesystem_error("cannot remove", p, ec)); return result; @@ -1263,14 +1263,6 @@ fs::remove(const path& p) bool fs::remove(const path& p, error_code& ec) noexcept { - const auto s = symlink_status(p, ec); - if (!status_known(s)) - return false; - if (s.type() == file_type::not_found) - { - ec.clear(); - return false; // Nothing to do, not an error. - } if (::remove(p.c_str()) == 0) { ec.clear(); @@ -1316,14 +1308,9 @@ fs::remove_all(const path& p, error_code& ec) return -1; } - if (::remove(p.c_str()) == 0) + if (fs::remove(p, ec)) ++count; - else if (errno != ENOENT) - { - ec.assign(errno, std::generic_category()); - return -1; - } - return count; + return ec ? -1 : count; } void -- 2.30.2