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
This commit is contained in:
parent
e59e183f69
commit
2be9212713
4 changed files with 73 additions and 8 deletions
|
@ -1,5 +1,12 @@
|
|||
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&&))
|
||||
(path::operator=(string&&), path::assign(string_type&&)): Define
|
||||
construction and assignment from string_type rvalues (LWG 2707).
|
||||
|
|
|
@ -112,6 +112,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
void current_path(const path& __p);
|
||||
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
|
||||
exists(file_status __s) noexcept
|
||||
{ return status_known(__s) && __s.type() != file_type::not_found; }
|
||||
|
@ -122,13 +128,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
|
||||
inline bool
|
||||
exists(const path& __p, error_code& __ec) noexcept
|
||||
{ return exists(status(__p, __ec)); }
|
||||
|
||||
bool
|
||||
equivalent(const path& __p1, const path& __p2);
|
||||
|
||||
bool
|
||||
equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept;
|
||||
{
|
||||
auto __s = status(__p, __ec);
|
||||
if (status_known(__s))
|
||||
__ec.clear();
|
||||
return exists(__s);
|
||||
}
|
||||
|
||||
uintmax_t file_size(const path& __p);
|
||||
uintmax_t file_size(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
|
||||
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;
|
||||
stat_type st;
|
||||
|
@ -1307,6 +1307,10 @@ fs::status(const fs::path& p, std::error_code& ec) noexcept
|
|||
ec.assign(err, std::generic_category());
|
||||
if (is_not_found_errno(err))
|
||||
status.type(file_type::not_found);
|
||||
#ifdef EOVERFLOW
|
||||
else if (err == EOVERFLOW)
|
||||
status.type(file_type::unknown);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -33,6 +33,18 @@ test01()
|
|||
VERIFY( exists(path{"."}) );
|
||||
VERIFY( exists(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
|
||||
|
@ -40,6 +52,10 @@ test02()
|
|||
{
|
||||
path rel = __gnu_test::nonexistent_path();
|
||||
VERIFY( !exists(rel) );
|
||||
|
||||
std::error_code ec = std::make_error_code(std::errc::invalid_argument);
|
||||
VERIFY( !exists(rel, ec) );
|
||||
VERIFY( !ec ); // DR 2725
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -47,6 +63,38 @@ test03()
|
|||
{
|
||||
path abs = absolute(__gnu_test::nonexistent_path());
|
||||
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
|
||||
|
@ -55,4 +103,5 @@ main()
|
|||
test01();
|
||||
test02();
|
||||
test03();
|
||||
test04();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue