diff options
author | Brad King <brad.king@kitware.com> | 2014-01-21 13:51:39 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2014-01-21 13:51:39 (GMT) |
commit | a86865e96c55c8a35615c24af0cf1c990f4bba68 (patch) | |
tree | d098ac097f26409ec2e3719c793449dbba3b74e6 /Source | |
parent | ce906497c011cf860e0aee2a1f9a4f1d4edc5397 (diff) | |
parent | e0228e2b04b3d6bf72304038c8621fc5072e7f4e (diff) | |
download | CMake-a86865e96c55c8a35615c24af0cf1c990f4bba68.zip CMake-a86865e96c55c8a35615c24af0cf1c990f4bba68.tar.gz CMake-a86865e96c55c8a35615c24af0cf1c990f4bba68.tar.bz2 |
Merge topic 'cmake-E-symlink-replace-dangling'
e0228e2b cmake: Improve '-E create_symlink' edge case handling (#14713)
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmcmd.cxx | 32 |
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. |