summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-05-11 13:28:42 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-05-11 13:28:49 (GMT)
commitee87e53d3732a6482841c01c16e89f2822137d0e (patch)
treecbff847dae36b1ea64de3a87f76ea743c72b5283
parent553cd4db44b5b735f9cb9a72f7b5d7fbb4212c12 (diff)
parentd0c31cbff94b86ae00fddac89c6f404cc4229370 (diff)
downloadCMake-ee87e53d3732a6482841c01c16e89f2822137d0e.zip
CMake-ee87e53d3732a6482841c01c16e89f2822137d0e.tar.gz
CMake-ee87e53d3732a6482841c01c16e89f2822137d0e.tar.bz2
Merge topic 'windows-artifact-symlinks'
d0c31cbff9 Windows: Use real artifact versioning symlinks if possible Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6093
-rw-r--r--Source/cmcmd.cxx15
1 files changed, 13 insertions, 2 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 30347f2..98946b6 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -1643,10 +1643,21 @@ cmsys::Status cmcmd::SymlinkInternal(std::string const& file,
if (cmSystemTools::FileExists(link) || cmSystemTools::FileIsSymlink(link)) {
cmSystemTools::RemoveFile(link);
}
+ std::string linktext = cmSystemTools::GetFilenameName(file);
#if defined(_WIN32) && !defined(__CYGWIN__)
- return cmSystemTools::CopyFileAlways(file, link);
+ std::string errorMessage;
+ cmsys::Status status =
+ cmSystemTools::CreateSymlink(linktext, link, &errorMessage);
+ // Creating a symlink will fail with ERROR_PRIVILEGE_NOT_HELD if the user
+ // does not have SeCreateSymbolicLinkPrivilege, or if developer mode is not
+ // active. In that case, we try to copy the file.
+ if (status.GetWindows() == ERROR_PRIVILEGE_NOT_HELD) {
+ status = cmSystemTools::CopyFileAlways(file, link);
+ } else if (!status) {
+ cmSystemTools::Error(errorMessage);
+ }
+ return status;
#else
- std::string linktext = cmSystemTools::GetFilenameName(file);
return cmSystemTools::CreateSymlink(linktext, link);
#endif
}