Commit 2be92127 by Jonathan Wakely Committed by Jonathan Wakely

LWG2725 Fix error reporting for filesystem::exists

	* include/experimental/bits/fs_ops.h
	(exists(const path&, error_code&)): Clear error if status is known
	(LWG 2725).
	(status(const path&, error_code&)): Handle EOVERFLOW.
	* testsuite/experimental/filesystem/operations/exists.cc: Test
	overload taking an error_code.

From-SVN: r241417
parent e59e183f
2016-10-21 Jonathan Wakely <jwakely@redhat.com> 2016-10-21 Jonathan Wakely <jwakely@redhat.com>
* include/experimental/bits/fs_ops.h
(exists(const path&, error_code&)): Clear error if status is known
(LWG 2725).
(status(const path&, error_code&)): Handle EOVERFLOW.
* testsuite/experimental/filesystem/operations/exists.cc: Test
overload taking an error_code.
* include/experimental/bits/fs_path.h (path::path(string_type&&)) * include/experimental/bits/fs_path.h (path::path(string_type&&))
(path::operator=(string&&), path::assign(string_type&&)): Define (path::operator=(string&&), path::assign(string_type&&)): Define
construction and assignment from string_type rvalues (LWG 2707). construction and assignment from string_type rvalues (LWG 2707).
......
...@@ -112,6 +112,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -112,6 +112,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void current_path(const path& __p); void current_path(const path& __p);
void current_path(const path& __p, error_code& __ec) noexcept; void current_path(const path& __p, error_code& __ec) noexcept;
bool
equivalent(const path& __p1, const path& __p2);
bool
equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept;
inline bool inline bool
exists(file_status __s) noexcept exists(file_status __s) noexcept
{ return status_known(__s) && __s.type() != file_type::not_found; } { return status_known(__s) && __s.type() != file_type::not_found; }
...@@ -122,13 +128,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -122,13 +128,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline bool inline bool
exists(const path& __p, error_code& __ec) noexcept exists(const path& __p, error_code& __ec) noexcept
{ return exists(status(__p, __ec)); } {
auto __s = status(__p, __ec);
bool if (status_known(__s))
equivalent(const path& __p1, const path& __p2); __ec.clear();
return exists(__s);
bool }
equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept;
uintmax_t file_size(const path& __p); uintmax_t file_size(const path& __p);
uintmax_t file_size(const path& __p, error_code& __ec) noexcept; uintmax_t file_size(const path& __p, error_code& __ec) noexcept;
......
...@@ -1297,7 +1297,7 @@ fs::space(const path& p, error_code& ec) noexcept ...@@ -1297,7 +1297,7 @@ fs::space(const path& p, error_code& ec) noexcept
#ifdef _GLIBCXX_HAVE_SYS_STAT_H #ifdef _GLIBCXX_HAVE_SYS_STAT_H
fs::file_status fs::file_status
fs::status(const fs::path& p, std::error_code& ec) noexcept fs::status(const fs::path& p, error_code& ec) noexcept
{ {
file_status status; file_status status;
stat_type st; stat_type st;
...@@ -1307,6 +1307,10 @@ fs::status(const fs::path& p, std::error_code& ec) noexcept ...@@ -1307,6 +1307,10 @@ fs::status(const fs::path& p, std::error_code& ec) noexcept
ec.assign(err, std::generic_category()); ec.assign(err, std::generic_category());
if (is_not_found_errno(err)) if (is_not_found_errno(err))
status.type(file_type::not_found); status.type(file_type::not_found);
#ifdef EOVERFLOW
else if (err == EOVERFLOW)
status.type(file_type::unknown);
#endif
} }
else else
{ {
......
...@@ -33,6 +33,18 @@ test01() ...@@ -33,6 +33,18 @@ test01()
VERIFY( exists(path{"."}) ); VERIFY( exists(path{"."}) );
VERIFY( exists(path{".."}) ); VERIFY( exists(path{".."}) );
VERIFY( exists(std::experimental::filesystem::current_path()) ); VERIFY( exists(std::experimental::filesystem::current_path()) );
std::error_code ec = std::make_error_code(std::errc::invalid_argument);
VERIFY( exists(path{"/"}, ec) );
VERIFY( !ec );
VERIFY( exists(path{"/."}, ec) );
VERIFY( !ec );
VERIFY( exists(path{"."}, ec) );
VERIFY( !ec );
VERIFY( exists(path{".."}, ec) );
VERIFY( !ec );
VERIFY( exists(std::experimental::filesystem::current_path(), ec) );
VERIFY( !ec );
} }
void void
...@@ -40,6 +52,10 @@ test02() ...@@ -40,6 +52,10 @@ test02()
{ {
path rel = __gnu_test::nonexistent_path(); path rel = __gnu_test::nonexistent_path();
VERIFY( !exists(rel) ); VERIFY( !exists(rel) );
std::error_code ec = std::make_error_code(std::errc::invalid_argument);
VERIFY( !exists(rel, ec) );
VERIFY( !ec ); // DR 2725
} }
void void
...@@ -47,6 +63,38 @@ test03() ...@@ -47,6 +63,38 @@ test03()
{ {
path abs = absolute(__gnu_test::nonexistent_path()); path abs = absolute(__gnu_test::nonexistent_path());
VERIFY( !exists(abs) ); VERIFY( !exists(abs) );
std::error_code ec = std::make_error_code(std::errc::invalid_argument);
VERIFY( !exists(abs, ec) );
VERIFY( !ec ); // DR 2725
}
void
test04()
{
using perms = std::experimental::filesystem::perms;
path p = __gnu_test::nonexistent_path();
create_directory(p);
permissions(p, perms::all | perms::remove_perms);
auto unr = p / "unreachable";
std::error_code ec;
VERIFY( !exists(unr, ec) );
VERIFY( ec == std::errc::permission_denied );
ec.clear();
try
{
exists(unr);
}
catch(const std::experimental::filesystem::filesystem_error& ex)
{
ec = ex.code();
VERIFY( ex.path1() == unr );
}
VERIFY( ec == std::errc::permission_denied );
permissions(p, perms::owner_all);
remove(p);
} }
int int
...@@ -55,4 +103,5 @@ main() ...@@ -55,4 +103,5 @@ main()
test01(); test01();
test02(); test02();
test03(); test03();
test04();
} }
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