diff options
-rw-r--r-- | Source/cmFileCommand.cxx | 20 | ||||
-rw-r--r-- | Source/cmSystemTools.cxx | 43 | ||||
-rw-r--r-- | Source/cmSystemTools.h | 10 | ||||
-rw-r--r-- | Source/cmcmd.cxx | 7 |
4 files changed, 50 insertions, 30 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index bec9fb2..421ff12 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -2960,11 +2960,23 @@ bool HandleCreateLinkCommand(std::vector<std::string> const& args, // Check if the command requires a symbolic link. if (arguments.Symbolic) { - completed = static_cast<bool>( - cmSystemTools::CreateSymlink(fileName, newFileName, &result)); + cmsys::Status linked = + cmSystemTools::CreateSymlinkQuietly(fileName, newFileName); + if (linked) { + completed = true; + } else { + result = cmStrCat("failed to create symbolic link '", newFileName, + "': ", linked.GetString()); + } } else { - completed = static_cast<bool>( - cmSystemTools::CreateLink(fileName, newFileName, &result)); + cmsys::Status linked = + cmSystemTools::CreateLinkQuietly(fileName, newFileName); + if (linked) { + completed = true; + } else { + result = cmStrCat("failed to create link '", newFileName, + "': ", linked.GetString()); + } } // Check if copy-on-error is enabled in the arguments. diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 5737cc1..ee74908 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -3590,8 +3590,19 @@ std::string cmSystemTools::EncodeURL(std::string const& in, bool escapeSlashes) } cmsys::Status cmSystemTools::CreateSymlink(std::string const& origName, - std::string const& newName, - std::string* errorMessage) + std::string const& newName) +{ + cmsys::Status status = + cmSystemTools::CreateSymlinkQuietly(origName, newName); + if (!status) { + cmSystemTools::Error(cmStrCat("failed to create symbolic link '", newName, + "': ", status.GetString())); + } + return status; +} + +cmsys::Status cmSystemTools::CreateSymlinkQuietly(std::string const& origName, + std::string const& newName) { uv_fs_t req; int flags = 0; @@ -3611,20 +3622,23 @@ cmsys::Status cmSystemTools::CreateSymlink(std::string const& origName, #else status = cmsys::Status::POSIX(-err); #endif - std::string e = cmStrCat("failed to create symbolic link '", newName, - "': ", status.GetString()); - if (errorMessage) { - *errorMessage = std::move(e); - } else { - cmSystemTools::Error(e); - } } return status; } cmsys::Status cmSystemTools::CreateLink(std::string const& origName, - std::string const& newName, - std::string* errorMessage) + std::string const& newName) +{ + cmsys::Status status = cmSystemTools::CreateLinkQuietly(origName, newName); + if (!status) { + cmSystemTools::Error( + cmStrCat("failed to create link '", newName, "': ", status.GetString())); + } + return status; +} + +cmsys::Status cmSystemTools::CreateLinkQuietly(std::string const& origName, + std::string const& newName) { uv_fs_t req; int err = @@ -3638,13 +3652,6 @@ cmsys::Status cmSystemTools::CreateLink(std::string const& origName, #else status = cmsys::Status::POSIX(-err); #endif - std::string e = - cmStrCat("failed to create link '", newName, "': ", status.GetString()); - if (errorMessage) { - *errorMessage = std::move(e); - } else { - cmSystemTools::Error(e); - } } return status; } diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index b02a977..87b354c 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -595,14 +595,16 @@ public: /** Create a symbolic link if the platform supports it. Returns whether creation succeeded. */ static cmsys::Status CreateSymlink(std::string const& origName, - std::string const& newName, - std::string* errorMessage = nullptr); + std::string const& newName); + static cmsys::Status CreateSymlinkQuietly(std::string const& origName, + std::string const& newName); /** Create a hard link if the platform supports it. Returns whether creation succeeded. */ static cmsys::Status CreateLink(std::string const& origName, - std::string const& newName, - std::string* errorMessage = nullptr); + std::string const& newName); + static cmsys::Status CreateLinkQuietly(std::string const& origName, + std::string const& newName); /** Get the system name. */ static cm::string_view GetSystemName(); diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 00c9bda..16944e6 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1700,16 +1700,15 @@ cmsys::Status cmcmd::SymlinkInternal(std::string const& file, } std::string linktext = cmSystemTools::GetFilenameName(file); #if defined(_WIN32) && !defined(__CYGWIN__) - std::string errorMessage; - cmsys::Status status = - cmSystemTools::CreateSymlink(linktext, link, &errorMessage); + cmsys::Status status = cmSystemTools::CreateSymlinkQuietly(linktext, link); // 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); + cmSystemTools::Error(cmStrCat("failed to create symbolic link '", link, + "': ", status.GetString())); } return status; #else |