1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-15 03:48:02 +08:00

cmSystemTools: Fix regression in input path normalization on Windows

Since commit 622596c6b2 (cmSystemTools: Re-implement
ToNormalizedPathOnDisk without translation map, 2024-10-30,
v4.0.0-rc1~528^2~5) we normalize input paths, while resolving symlinks
only if followed by `..` components, by using `cm::PathResolver`'s
`LogicalPath` mode.  However, that approach assumes POSIX semantics for
resolving paths with symlinks and is incorrect on Windows.

On Windows, file system operations naively remove any component
preceding `..` regardless of whether it is a symlink.  Prior to the
above commit, `ToNormalizedPathOnDisk` matched that behavior using
`CollapseFullPath` followed by `GetActualCaseForPath`.  Restore it using
`cm::PathResolver`'s `CasePath` mode.

Issue: #26750
This commit is contained in:
Brad King
2025-03-07 15:07:20 -05:00
parent 8dfc725cdb
commit fc5584f9bb

View File

@@ -1991,8 +1991,13 @@ std::vector<std::string> cmSystemTools::SplitEnvPathNormalized(
std::string cmSystemTools::ToNormalizedPathOnDisk(std::string p) std::string cmSystemTools::ToNormalizedPathOnDisk(std::string p)
{ {
using namespace cm::PathResolver; using namespace cm::PathResolver;
#ifdef _WIN32
// IWYU pragma: no_forward_declare cm::PathResolver::Policies::CasePath
static Resolver<Policies::CasePath> const resolver(RealOS);
#else
// IWYU pragma: no_forward_declare cm::PathResolver::Policies::LogicalPath // IWYU pragma: no_forward_declare cm::PathResolver::Policies::LogicalPath
static Resolver<Policies::LogicalPath> const resolver(RealOS); static Resolver<Policies::LogicalPath> const resolver(RealOS);
#endif
resolver.Resolve(std::move(p), p); resolver.Resolve(std::move(p), p);
return p; return p;
} }