Implement LWG 2937 - equivalent("dne", "exists") is not an error

This patch speculatively implements the PR for LWG 2937, which fixes
two issues with equivalent.

(1) It makes equivalent("dne", "exists") an error. Previously only
    equivalent("dne", "dne") was an error and the former case was not (it returned false).
    Now equivalent reports an error when either input doesn't exist.

(2) It makes equivalent(p1, p2) well-formed when `is_other(p1) && is_other(p2)`.
    Previously this was an error, but there is seemingly no reason why it should be on POSIX system.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@307117 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2017-07-05 03:37:05 +00:00
parent c5247b417b
commit 3288eac673
3 changed files with 86 additions and 59 deletions

View File

@@ -426,17 +426,20 @@ void __current_path(const path& p, std::error_code *ec) {
bool __equivalent(const path& p1, const path& p2, std::error_code *ec)
{
auto make_unsupported_error = [&]() {
set_or_throw(make_error_code(errc::not_supported), ec,
"equivalent", p1, p2);
return false;
};
std::error_code ec1, ec2;
struct ::stat st1 = {};
struct ::stat st2 = {};
auto s1 = detail::posix_stat(p1.native(), st1, &ec1);
if (!exists(s1))
return make_unsupported_error();
auto s2 = detail::posix_stat(p2.native(), st2, &ec2);
if ((!exists(s1) && !exists(s2)) || (is_other(s1) && is_other(s2))) {
set_or_throw(make_error_code(errc::not_supported), ec,
"equivalent", p1, p2);
return false;
}
if (!exists(s2))
return make_unsupported_error();
if (ec) ec->clear();
return (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino);
}