Given an existing directory called "example", std::filesystem apparently
behaves like this on Windows:
std::filesystem::exists("example") -> true
std::filesystem::exists("example/") -> true
std::filesystem::exists("example\\") -> true
std::filesystem::equivalent("example", "example") -> true
std::filesystem::equivalent("example", "example/") -> false
std::filesystem::equivalent("example", "example\\") -> false
That's... well, unexpected. This makes util::make_relative_path buggy.
Fix this by pruning the trailing slash after normalizing the path.
Fixes #1518.
DEBUG_ASSERT(path.is_absolute());
fs::path normalized_path = path.lexically_normal();
+ if (!normalized_path.has_filename()) {
+ // Skip trailing slash since fs::equivalent doesn't work otherwise on
+ // Windows.
+ normalized_path = normalized_path.parent_path();
+ }
fs::path closest_existing_path = normalized_path;
std::vector<fs::path> relpath_candidates;
fs::path path_suffix;
SUBCASE("Match of actual CWD")
{
+ REQUIRE(fs::create_directory("d"));
+
CHECK(make_relative_path(actual_cwd, apparent_cwd, actual_cwd + "/x")
== "x");
CHECK(make_relative_path(actual_cwd, apparent_cwd, actual_cwd + "/d")