MCPcopy Create free account
hub / github.com/Kitware/CMake / GetRealPath

Method GetRealPath

Source/cmSystemTools.cxx:1350–1394  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1348}
1349
1350std::string cmSystemTools::GetRealPath(std::string const& path,
1351 std::string* errorMessage)
1352{
1353#ifdef _WIN32
1354 std::string resolved_path =
1355 cmSystemTools::GetRealPathResolvingWindowsSubst(path, errorMessage);
1356
1357 // If the original path used a subst drive and the real path starts
1358 // with the substitution, restore the subst drive prefix. This may
1359 // incorrectly restore a subst drive if the underlying drive was
1360 // encountered via an absolute symlink, but this is an acceptable
1361 // limitation to otherwise preserve susbt drives.
1362 if (resolved_path.size() >= 2 && resolved_path[1] == ':' &&
1363 path.size() >= 2 && path[1] == ':' &&
1364 cmsysString_toupper(resolved_path[0]) != cmsysString_toupper(path[0])) {
1365 // FIXME: Add thread_local or mutex if we use threads.
1366 static std::map<char, std::string> substMap;
1367 char const drive = static_cast<char>(cmsysString_toupper(path[0]));
1368 std::string maybe_subst = cmStrCat(drive, ":/");
1369 auto smi = substMap.find(drive);
1370 if (smi == substMap.end()) {
1371 smi = substMap
1372 .emplace(
1373 drive,
1374 cmSystemTools::GetRealPathResolvingWindowsSubst(maybe_subst))
1375 .first;
1376 }
1377 std::string const& resolved_subst = smi->second;
1378 std::string::size_type const ns = resolved_subst.size();
1379 if (ns > 0) {
1380 std::string::size_type const np = resolved_path.size();
1381 if (ns == np && resolved_path == resolved_subst) {
1382 resolved_path = maybe_subst;
1383 } else if (ns > 0 && ns < np && resolved_path[ns] == '/' &&
1384 resolved_path.compare(0, ns, resolved_subst) == 0) {
1385 resolved_path.replace(0, ns + 1, maybe_subst);
1386 }
1387 }
1388 }
1389
1390 return resolved_path;
1391#else
1392 return cmsys::SystemTools::GetRealPath(path, errorMessage);
1393#endif
1394}
1395
1396void cmSystemTools::InitializeLibUV()
1397{

Callers 4

IsImplicitDirectoryMethod · 0.45
IsSameDirectoryMethod · 0.45

Calls 7

GetRealPathFunction · 0.85
emplaceMethod · 0.80
cmStrCatFunction · 0.70
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
compareMethod · 0.45

Tested by

no test coverage detected