summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2016-10-24 16:45:55 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2016-10-24 16:45:55 +0000
commit9e94ae7fe7b1ccac8067e21e6b74e60045a02861 (patch)
tree512d1099877f7738338a4b5227574b47cfa24b7e
parent10709260fa785a45441e59ceb86eb129ae3e13b1 (diff)
downloadgcc-9e94ae7fe7b1ccac8067e21e6b74e60045a02861.tar.gz
Fix error handling in filesystem::is_empty
* src/filesystem/ops.cc (is_empty): Fix error handling. * testsuite/experimental/filesystem/operations/is_empty.cc: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241488 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog3
-rw-r--r--libstdc++-v3/src/filesystem/ops.cc14
2 files changed, 12 insertions, 5 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index bc9a215e20a..e551d392da1 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,8 @@
2016-10-24 Jonathan Wakely <jwakely@redhat.com>
+ * src/filesystem/ops.cc (is_empty): Fix error handling.
+ * testsuite/experimental/filesystem/operations/is_empty.cc: New test.
+
PR libstdc++/71337
* src/filesystem/ops.cc (temp_directory_path): Pass error_code
argument to other filesystem operations.
diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc
index 90c225b0339..d9a12df5fa2 100644
--- a/libstdc++-v3/src/filesystem/ops.cc
+++ b/libstdc++-v3/src/filesystem/ops.cc
@@ -1022,20 +1022,24 @@ fs::hard_link_count(const path& p, error_code& ec) noexcept
bool
fs::is_empty(const path& p)
{
- return fs::is_directory(status(p))
- ? fs::directory_iterator(p) == fs::directory_iterator()
- : fs::file_size(p) == 0;
+ error_code ec;
+ bool e = is_empty(p, ec);
+ if (ec)
+ _GLIBCXX_THROW_OR_ABORT(filesystem_error("cannot check is file is empty",
+ p, ec));
+ return e;
}
bool
fs::is_empty(const path& p, error_code& ec) noexcept
{
auto s = status(p, ec);
- if (ec.value())
+ if (ec)
return false;
- return fs::is_directory(s)
+ bool empty = fs::is_directory(s)
? fs::directory_iterator(p, ec) == fs::directory_iterator()
: fs::file_size(p, ec) == 0;
+ return ec ? false : empty;
}
fs::file_time_type