Commit 94caf860 by Jonathan Wakely Committed by Jonathan Wakely

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.

From-SVN: r241488
parent 6daff2d9
2016-10-24 Jonathan Wakely <jwakely@redhat.com> 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 PR libstdc++/71337
* src/filesystem/ops.cc (temp_directory_path): Pass error_code * src/filesystem/ops.cc (temp_directory_path): Pass error_code
argument to other filesystem operations. argument to other filesystem operations.
......
...@@ -1022,20 +1022,24 @@ fs::hard_link_count(const path& p, error_code& ec) noexcept ...@@ -1022,20 +1022,24 @@ fs::hard_link_count(const path& p, error_code& ec) noexcept
bool bool
fs::is_empty(const path& p) fs::is_empty(const path& p)
{ {
return fs::is_directory(status(p)) error_code ec;
? fs::directory_iterator(p) == fs::directory_iterator() bool e = is_empty(p, ec);
: fs::file_size(p) == 0; if (ec)
_GLIBCXX_THROW_OR_ABORT(filesystem_error("cannot check is file is empty",
p, ec));
return e;
} }
bool bool
fs::is_empty(const path& p, error_code& ec) noexcept fs::is_empty(const path& p, error_code& ec) noexcept
{ {
auto s = status(p, ec); auto s = status(p, ec);
if (ec.value()) if (ec)
return false; return false;
return fs::is_directory(s) bool empty = fs::is_directory(s)
? fs::directory_iterator(p, ec) == fs::directory_iterator() ? fs::directory_iterator(p, ec) == fs::directory_iterator()
: fs::file_size(p, ec) == 0; : fs::file_size(p, ec) == 0;
return ec ? false : empty;
} }
fs::file_time_type fs::file_time_type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment