summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-10-25 12:14:47 (GMT)
committerKitware Robot <kwrobot@kitware.com>2017-10-25 12:14:55 (GMT)
commite419a67a56ff33f82498073c91e533981a9fb2d1 (patch)
treed1c3de30c0782482dc4fcb8f08c497fc803facce /Source
parentfe4d6f1fd6a0af755e30e71430082667f9683e5e (diff)
parent393e0fbe630a698d9c8c972059e5de1da727f76a (diff)
downloadCMake-e419a67a56ff33f82498073c91e533981a9fb2d1.zip
CMake-e419a67a56ff33f82498073c91e533981a9fb2d1.tar.gz
CMake-e419a67a56ff33f82498073c91e533981a9fb2d1.tar.bz2
Merge topic 'windows_symlinks'
393e0fbe cmTimestamp: For symlinks switch to timestamp of resolved path 640709e7 cmSystemTools: Implement GetRealPath on Windows d41582fc Call GetRealPath through cmSystemTools instead of KWSys directly Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !1202
Diffstat (limited to 'Source')
-rw-r--r--Source/cmFilePathChecksum.cxx10
-rw-r--r--Source/cmSystemTools.cxx35
-rw-r--r--Source/cmSystemTools.h4
-rw-r--r--Source/cmTimestamp.cxx6
4 files changed, 48 insertions, 7 deletions
diff --git a/Source/cmFilePathChecksum.cxx b/Source/cmFilePathChecksum.cxx
index f9afeef..f84360e 100644
--- a/Source/cmFilePathChecksum.cxx
+++ b/Source/cmFilePathChecksum.cxx
@@ -34,10 +34,10 @@ void cmFilePathChecksum::setupParentDirs(std::string const& currentSrcDir,
std::string const& projectSrcDir,
std::string const& projectBinDir)
{
- this->parentDirs[0].first = cmsys::SystemTools::GetRealPath(currentSrcDir);
- this->parentDirs[1].first = cmsys::SystemTools::GetRealPath(currentBinDir);
- this->parentDirs[2].first = cmsys::SystemTools::GetRealPath(projectSrcDir);
- this->parentDirs[3].first = cmsys::SystemTools::GetRealPath(projectBinDir);
+ this->parentDirs[0].first = cmSystemTools::GetRealPath(currentSrcDir);
+ this->parentDirs[1].first = cmSystemTools::GetRealPath(currentBinDir);
+ this->parentDirs[2].first = cmSystemTools::GetRealPath(projectSrcDir);
+ this->parentDirs[3].first = cmSystemTools::GetRealPath(projectBinDir);
this->parentDirs[0].second = "CurrentSource";
this->parentDirs[1].second = "CurrentBinary";
@@ -50,7 +50,7 @@ std::string cmFilePathChecksum::get(std::string const& filePath) const
std::string relPath;
std::string relSeed;
{
- std::string const fileReal = cmsys::SystemTools::GetRealPath(filePath);
+ std::string const fileReal = cmSystemTools::GetRealPath(filePath);
std::string parentDir;
// Find closest project parent directory
for (auto const& pDir : this->parentDirs) {
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 63c1452..5d1f5f7 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -50,6 +50,8 @@
#include <windows.h>
// include wincrypt.h after windows.h
#include <wincrypt.h>
+
+#include "cm_uv.h"
#else
#include <sys/time.h>
#include <unistd.h>
@@ -943,6 +945,39 @@ cmSystemTools::WindowsFileRetry cmSystemTools::GetWindowsFileRetry()
}
return retry;
}
+
+std::string cmSystemTools::GetRealPath(const std::string& path,
+ std::string* errorMessage)
+{
+ // uv_fs_realpath uses Windows Vista API so fallback to kwsys if not found
+ std::string resolved_path;
+ uv_fs_t req;
+ int err = uv_fs_realpath(NULL, &req, path.c_str(), NULL);
+ if (!err) {
+ resolved_path = std::string((char*)req.ptr);
+ cmSystemTools::ConvertToUnixSlashes(resolved_path);
+ // Normalize to upper-case drive letter as GetActualCaseForPath does.
+ if (resolved_path.size() > 1 && resolved_path[1] == ':') {
+ resolved_path[0] = toupper(resolved_path[0]);
+ }
+ } else if (err == UV_ENOSYS) {
+ resolved_path = cmsys::SystemTools::GetRealPath(path, errorMessage);
+ } else if (errorMessage) {
+ LPSTR message = NULL;
+ DWORD size = FormatMessageA(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&message, 0,
+ NULL);
+ *errorMessage = std::string(message, size);
+ LocalFree(message);
+
+ resolved_path = "";
+ } else {
+ resolved_path = path;
+ }
+ return resolved_path;
+}
#endif
bool cmSystemTools::RenameFile(const char* oldname, const char* newname)
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index e7082e6..2646df9 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -497,6 +497,10 @@ public:
unsigned int Delay;
};
static WindowsFileRetry GetWindowsFileRetry();
+
+ /** Get the real path for a given path, removing all symlinks. */
+ static std::string GetRealPath(const std::string& path,
+ std::string* errorMessage = 0);
#endif
private:
static bool s_ForceUnixPaths;
diff --git a/Source/cmTimestamp.cxx b/Source/cmTimestamp.cxx
index 9fb79d9..e747adb 100644
--- a/Source/cmTimestamp.cxx
+++ b/Source/cmTimestamp.cxx
@@ -33,11 +33,13 @@ std::string cmTimestamp::FileModificationTime(const char* path,
const std::string& formatString,
bool utcFlag)
{
- if (!cmsys::SystemTools::FileExists(path)) {
+ std::string real_path = cmSystemTools::GetRealPath(path);
+
+ if (!cmsys::SystemTools::FileExists(real_path)) {
return std::string();
}
- time_t mtime = cmsys::SystemTools::ModifiedTime(path);
+ time_t mtime = cmsys::SystemTools::ModifiedTime(real_path);
return CreateTimestampFromTimeT(mtime, formatString, utcFlag);
}