equivalent() now compares filesystem identity only; added related tests, refs #210

This commit is contained in:
Steffen Schümann 2026-07-14 23:13:53 +02:00
parent 796515b6be
commit 29b5acd3d6
3 changed files with 17 additions and 5 deletions

View File

@ -526,7 +526,7 @@ C++11/14. Starting with v1.1.0 these are supported when compiling
`ghc::filesystem` under C++17 of C++20. `ghc::filesystem` under C++17 of C++20.
Starting with v1.5.2 `ghc::filesystem` will try to allow the use of Starting with v1.5.2 `ghc::filesystem` will try to allow the use of
`std::experimental::basic_string_view` where it detects is availability. `std::experimental::basic_string_view` where it detects its availability.
Additionally if you have a `basic_string_view` compatible c++11 Additionally if you have a `basic_string_view` compatible c++11
implementation it can be used instead of `std::basic_string_view` implementation it can be used instead of `std::basic_string_view`
by defining `GHC_HAS_CUSTOM_STRING_VIEW` and importing the by defining `GHC_HAS_CUSTOM_STRING_VIEW` and importing the
@ -633,7 +633,7 @@ the standard.
As symbolic links on Windows, while being supported more or less since As symbolic links on Windows, while being supported more or less since
Windows Vista (with some strict security constraints) and fully since some earlier Windows Vista (with some strict security constraints) and fully since some earlier
build of Windows 10, when "Developer Mode" is activated, are at time of writing build of Windows 10, when "Developer Mode" is activated, are at time of writing
(2018) rarely used, still they are supported wiit th this implementation. (2018) rarely used, still they are supported with this implementation.
#### Permissions #### Permissions
@ -671,6 +671,8 @@ to the expected behavior.
metadata now preserves subsecond modification times. metadata now preserves subsecond modification times.
* Fix for [#209](https://github.com/gulrak/filesystem/issues/209), malformed * Fix for [#209](https://github.com/gulrak/filesystem/issues/209), malformed
UTF-16 no longer drops subsequent valid code units. UTF-16 no longer drops subsequent valid code units.
* Fix for [#210](https://github.com/gulrak/filesystem/issues/210),
`equivalent()` now compares only filesystem identity.
* Fix for [#178](https://github.com/gulrak/filesystem/issues/178), recursive * Fix for [#178](https://github.com/gulrak/filesystem/issues/178), recursive
iteration no longer resolves symlinks unless requested. iteration no longer resolves symlinks unless requested.
* Fix for [#185](https://github.com/gulrak/filesystem/issues/185), * Fix for [#185](https://github.com/gulrak/filesystem/issues/185),

View File

@ -4392,8 +4392,7 @@ GHC_INLINE bool equivalent(const path& p1, const path& p2, std::error_code& ec)
ec = detail::make_system_error(); ec = detail::make_system_error();
return false; return false;
} }
return inf1.ftLastWriteTime.dwLowDateTime == inf2.ftLastWriteTime.dwLowDateTime && inf1.ftLastWriteTime.dwHighDateTime == inf2.ftLastWriteTime.dwHighDateTime && inf1.nFileIndexHigh == inf2.nFileIndexHigh && inf1.nFileIndexLow == inf2.nFileIndexLow && return inf1.nFileIndexHigh == inf2.nFileIndexHigh && inf1.nFileIndexLow == inf2.nFileIndexLow && inf1.dwVolumeSerialNumber == inf2.dwVolumeSerialNumber;
inf1.nFileSizeHigh == inf2.nFileSizeHigh && inf1.nFileSizeLow == inf2.nFileSizeLow && inf1.dwVolumeSerialNumber == inf2.dwVolumeSerialNumber;
#else #else
struct ::stat s1, s2; struct ::stat s1, s2;
auto rc1 = ::stat(p1.c_str(), &s1); auto rc1 = ::stat(p1.c_str(), &s1);
@ -4409,7 +4408,7 @@ GHC_INLINE bool equivalent(const path& p1, const path& p2, std::error_code& ec)
#endif #endif
return false; return false;
} }
return s1.st_dev == s2.st_dev && s1.st_ino == s2.st_ino && s1.st_size == s2.st_size && s1.st_mtime == s2.st_mtime; return s1.st_dev == s2.st_dev && s1.st_ino == s2.st_ino;
#endif #endif
} }

View File

@ -2102,6 +2102,17 @@ TEST_CASE("fs.op.equivalent - equivalent", "[filesystem][operations][fs.op.equiv
CHECK(fs::equivalent("foo", "foo2", ec)); CHECK(fs::equivalent("foo", "foo2", ec));
CHECK(!ec); CHECK(!ec);
} }
fs::create_hard_link("foo", "foo-hard-link");
CHECK(fs::equivalent("foo", "foo-hard-link"));
generateFile("foo-hard-link", 4321);
CHECK(fs::file_size("foo") == 4321);
CHECK(fs::equivalent("foo", "foo-hard-link"));
std::error_code mutationEc(42, std::system_category());
CHECK(fs::equivalent("foo", "foo-hard-link", mutationEc));
CHECK(!mutationEc);
if (is_symlink_creation_supported()) {
CHECK(fs::equivalent("foo", "foo2"));
}
#ifdef TEST_LWG_2937_BEHAVIOUR #ifdef TEST_LWG_2937_BEHAVIOUR
INFO("This test expects LWG #2937 result conformance."); INFO("This test expects LWG #2937 result conformance.");
std::error_code ec; std::error_code ec;