summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-07-16 14:18:51 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-07-16 14:19:12 (GMT)
commitc7b7547d8da6b9a4225d111440d0cf6c2f55914d (patch)
treee5ecbea753d879f1d7d8c7a2e9f58dffe3f8dc5f /Source
parent4662c041eac50888d445a77ed091f395cafe61fe (diff)
parent2fad00940d7ed3c5928bda5b671bdcf08ce53bb8 (diff)
downloadCMake-c7b7547d8da6b9a4225d111440d0cf6c2f55914d.zip
CMake-c7b7547d8da6b9a4225d111440d0cf6c2f55914d.tar.gz
CMake-c7b7547d8da6b9a4225d111440d0cf6c2f55914d.tar.bz2
Merge topic 'cmake-E-create_hardlink'
2fad00940d cmake: Add -E create_hardlink Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5015
Diffstat (limited to 'Source')
-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;