From 7f89053953f81aaa3d0283ba4b8d8b29ce234292 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 15 Apr 2021 12:31:41 -0400 Subject: cmSystemTools: Return KWSys Status from CreateLink and CreateSymlink --- Source/cmFileCommand.cxx | 6 ++++-- Source/cmSystemTools.cxx | 24 ++++++++++++------------ Source/cmSystemTools.h | 12 ++++++------ 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 26bdedf..05ebcca 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -2949,9 +2949,11 @@ bool HandleCreateLinkCommand(std::vector const& args, // Check if the command requires a symbolic link. if (arguments.Symbolic) { - completed = cmSystemTools::CreateSymlink(fileName, newFileName, &result); + completed = static_cast( + cmSystemTools::CreateSymlink(fileName, newFileName, &result)); } else { - completed = cmSystemTools::CreateLink(fileName, newFileName, &result); + completed = static_cast( + cmSystemTools::CreateLink(fileName, newFileName, &result)); } // Check if copy-on-error is enabled in the arguments. diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 2b3266d..5382fac 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -3158,9 +3158,9 @@ std::string cmSystemTools::EncodeURL(std::string const& in, bool escapeSlashes) return out; } -bool cmSystemTools::CreateSymlink(const std::string& origName, - const std::string& newName, - std::string* errorMessage) +cmsys::Status cmSystemTools::CreateSymlink(std::string const& origName, + std::string const& newName, + std::string* errorMessage) { uv_fs_t req; int flags = 0; @@ -3171,7 +3171,9 @@ bool cmSystemTools::CreateSymlink(const std::string& origName, #endif int err = uv_fs_symlink(nullptr, &req, origName.c_str(), newName.c_str(), flags, nullptr); + cmsys::Status status; if (err) { + status = cmsys::Status::POSIX(-err); std::string e = "failed to create symbolic link '" + newName + "': " + uv_strerror(err); if (errorMessage) { @@ -3179,20 +3181,20 @@ bool cmSystemTools::CreateSymlink(const std::string& origName, } else { cmSystemTools::Error(e); } - return false; } - - return true; + return status; } -bool cmSystemTools::CreateLink(const std::string& origName, - const std::string& newName, - std::string* errorMessage) +cmsys::Status cmSystemTools::CreateLink(std::string const& origName, + std::string const& newName, + std::string* errorMessage) { uv_fs_t req; int err = uv_fs_link(nullptr, &req, origName.c_str(), newName.c_str(), nullptr); + cmsys::Status status; if (err) { + status = cmsys::Status::POSIX(-err); std::string e = "failed to create link '" + newName + "': " + uv_strerror(err); if (errorMessage) { @@ -3200,10 +3202,8 @@ bool cmSystemTools::CreateLink(const std::string& origName, } else { cmSystemTools::Error(e); } - return false; } - - return true; + return status; } cm::string_view cmSystemTools::GetSystemName() diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 99f20e0..0aecf71 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -489,15 +489,15 @@ public: /** Create a symbolic link if the platform supports it. Returns whether creation succeeded. */ - static bool CreateSymlink(const std::string& origName, - const std::string& newName, - std::string* errorMessage = nullptr); + static cmsys::Status CreateSymlink(std::string const& origName, + std::string const& newName, + std::string* errorMessage = nullptr); /** Create a hard link if the platform supports it. Returns whether creation succeeded. */ - static bool CreateLink(const std::string& origName, - const std::string& newName, - std::string* errorMessage = nullptr); + static cmsys::Status CreateLink(std::string const& origName, + std::string const& newName, + std::string* errorMessage = nullptr); /** Get the system name. */ static cm::string_view GetSystemName(); -- cgit v0.12