summaryrefslogtreecommitdiffstats
path: root/Source/cmcmd.cxx
diff options
context:
space:
mode:
authorSibi Siddharthan <sibisiddharthan.github@gmail.com>2020-07-14 16:24:04 (GMT)
committerSibi Siddharthan <sibisiddharthan.github@gmail.com>2020-07-15 14:52:04 (GMT)
commit2fad00940d7ed3c5928bda5b671bdcf08ce53bb8 (patch)
tree16ed66550694ac2eb00aadfc95098b3c30b8236d /Source/cmcmd.cxx
parent2da778664d3e99ada4e67a5a1b9d377f92a9f75f (diff)
downloadCMake-2fad00940d7ed3c5928bda5b671bdcf08ce53bb8.zip
CMake-2fad00940d7ed3c5928bda5b671bdcf08ce53bb8.tar.gz
CMake-2fad00940d7ed3c5928bda5b671bdcf08ce53bb8.tar.bz2
cmake: Add -E create_hardlink
Fixes: #20950 Signed-off-by: Sibi Siddharthan <sibisiddharthan.github@gmail.com>
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r--Source/cmcmd.cxx29
1 files changed, 29 insertions, 0 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 49e8a4f..1a5fea1 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -126,6 +126,7 @@ void CMakeCommandUsage(const char* program)
<< " touch <file>... - touch a <file>.\n"
<< " touch_nocreate <file>... - touch a <file> but do not create it.\n"
<< " create_symlink old new - create a symbolic link new -> old\n"
+ << " create_hardlink old new - create a hard link new -> old\n"
<< " true - do nothing with an exit code of 0\n"
<< " false - do nothing with an exit code of 1\n"
#if defined(_WIN32) && !defined(__CYGWIN__)
@@ -1034,6 +1035,34 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args)
return 0;
}
+ // Command to create a hard link. Fails on platforms not
+ // supporting them.
+ if (args[1] == "create_hardlink" && args.size() == 4) {
+ const char* SouceFileName = args[2].c_str();
+ const char* destinationFileName = args[3].c_str();
+
+ if (!cmSystemTools::FileExists(SouceFileName)) {
+ std::cerr << "failed to create hard link because source path '"
+ << SouceFileName << "' does not exist \n";
+ return 1;
+ }
+
+ if ((cmSystemTools::FileExists(destinationFileName) ||
+ cmSystemTools::FileIsSymlink(destinationFileName)) &&
+ !cmSystemTools::RemoveFile(destinationFileName)) {
+ std::string emsg = cmSystemTools::GetLastSystemError();
+ std::cerr << "failed to create hard link '" << destinationFileName
+ << "' because existing path cannot be removed: " << emsg
+ << "\n";
+ return 1;
+ }
+
+ if (!cmSystemTools::CreateLink(args[2], args[3])) {
+ return 1;
+ }
+ return 0;
+ }
+
// Command to do nothing with an exit code of 0.
if (args[1] == "true") {
return 0;