summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-01-20 18:50:31 (GMT)
committerBrad King <brad.king@kitware.com>2014-01-20 19:02:21 (GMT)
commite0228e2b04b3d6bf72304038c8621fc5072e7f4e (patch)
tree4bfc57e8ee9240fd8076ed5567731d01ff692fb4 /Source
parentd4ca30ae150ea83c91bb75527a4152ce87e289e5 (diff)
downloadCMake-e0228e2b04b3d6bf72304038c8621fc5072e7f4e.zip
CMake-e0228e2b04b3d6bf72304038c8621fc5072e7f4e.tar.gz
CMake-e0228e2b04b3d6bf72304038c8621fc5072e7f4e.tar.bz2
cmake: Improve '-E create_symlink' edge case handling (#14713)
The logic added by commit ffc0b5e4 (Overwrite the symlink if it already exists, 2007-02-15) does not recognize and remove existing broken links before replacing them. Improve the logic to remove any existing destination file or link (but not directory). On failure, report an error message explaining why the existing path could not be removed or the new one could not be created. Add a RunCMake.CommandLine test to cover 'cmake -E' cases. Start with test cases covering 'cmake -E create_symlink' behavior on UNIX platforms.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmcmd.cxx32
1 files changed, 17 insertions, 15 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 7891969..c1576c4 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -460,23 +460,25 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
else if (args[1] == "create_symlink" && args.size() == 4)
{
const char* destinationFileName = args[3].c_str();
- if ( cmSystemTools::FileExists(destinationFileName) )
+ if((cmSystemTools::FileExists(destinationFileName) ||
+ cmSystemTools::FileIsSymlink(destinationFileName)) &&
+ !cmSystemTools::RemoveFile(destinationFileName))
{
- if ( cmSystemTools::FileIsSymlink(destinationFileName) )
- {
- if ( !cmSystemTools::RemoveFile(destinationFileName) ||
- cmSystemTools::FileExists(destinationFileName) )
- {
- return 0;
- }
- }
- else
- {
- return 0;
- }
+ std::string emsg = cmSystemTools::GetLastSystemError();
+ std::cerr <<
+ "failed to create symbolic link '" << destinationFileName <<
+ "' because existing path cannot be removed: " << emsg << "\n";
+ return 1;
+ }
+ if(!cmSystemTools::CreateSymlink(args[2].c_str(), args[3].c_str()))
+ {
+ std::string emsg = cmSystemTools::GetLastSystemError();
+ std::cerr <<
+ "failed to create symbolic link '" << destinationFileName <<
+ "': " << emsg << "\n";
+ return 1;
}
- return cmSystemTools::CreateSymlink(args[2].c_str(),
- args[3].c_str())? 0:1;
+ return 0;
}
// Internal CMake shared library support.