summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2016-10-21 17:00:59 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2016-10-21 17:00:59 +0000
commitd0cdffaea0693484f42073c38fb73b124a81a521 (patch)
treeb8178b78f1624dff2b5fe484dcb72077cf54e82a
parente496648ec673d36e422c0c4ea4e352719ed6b81e (diff)
downloadgcc-d0cdffaea0693484f42073c38fb73b124a81a521.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241417 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog7
-rw-r--r--libstdc++-v3/include/experimental/bits/fs_ops.h19
-rw-r--r--libstdc++-v3/src/filesystem/ops.cc6
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc49
4 files changed, 73 insertions, 8 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 7fb055ded2b..d4250ee529a 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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).
diff --git a/libstdc++-v3/include/experimental/bits/fs_ops.h b/libstdc++-v3/include/experimental/bits/fs_ops.h
index 8506b091c87..62a9826d6e5 100644
--- a/libstdc++-v3/include/experimental/bits/fs_ops.h
+++ b/libstdc++-v3/include/experimental/bits/fs_ops.h
@@ -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;
diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc
index 659cfbb6f81..6b38584bff8 100644
--- a/libstdc++-v3/src/filesystem/ops.cc
+++ b/libstdc++-v3/src/filesystem/ops.cc
@@ -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
{
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc
index 0eaa671d552..7dbc8e96db9 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc
@@ -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();
}