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).
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; }
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;
#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;
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
{
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
{
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
{
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
test01();
test02();
test03();
+ test04();
}