summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-05-06 14:39:05 (GMT)
committerBrad King <brad.king@kitware.com>2021-05-07 12:30:52 (GMT)
commitd7522b8f864db8df25b99eeabc625e55ad690a3e (patch)
tree6f9bc3bcbc373f103696c8c20565b45d7c6a45cf /Source/cmSystemTools.cxx
parente0b4a22ca6874a15912eea86cde16f47cb5f9d93 (diff)
downloadCMake-d7522b8f864db8df25b99eeabc625e55ad690a3e.zip
CMake-d7522b8f864db8df25b99eeabc625e55ad690a3e.tar.gz
CMake-d7522b8f864db8df25b99eeabc625e55ad690a3e.tar.bz2
cmSystemTools: Improve CreateLink and CreateSymlink error codes
In commit 7f89053953 (cmSystemTools: Return KWSys Status from CreateLink and CreateSymlink, 2021-04-15) we just took the `-err` from libuv and treated it as a POSIX error. This is accurate on POSIX, but on Windows does not match the POSIX error codes. Use `uv_fs_get_system_error` to get the actual system error code. This requires libuv 1.38 or higher. Require that for Windows, but fall back to the previous approach on POSIX.
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx18
1 files changed, 15 insertions, 3 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 9e46dab..ab42810 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -3173,9 +3173,15 @@ cmsys::Status cmSystemTools::CreateSymlink(std::string const& origName,
flags, nullptr);
cmsys::Status status;
if (err) {
+#if defined(_WIN32)
+ status = cmsys::Status::Windows(uv_fs_get_system_error(&req));
+#elif UV_VERSION_MAJOR > 1 || (UV_VERSION_MAJOR == 1 && UV_VERSION_MINOR >= 38)
+ status = cmsys::Status::POSIX(uv_fs_get_system_error(&req));
+#else
status = cmsys::Status::POSIX(-err);
- std::string e =
- "failed to create symbolic link '" + newName + "': " + uv_strerror(err);
+#endif
+ std::string e = cmStrCat("failed to create symbolic link '", newName,
+ "': ", status.GetString());
if (errorMessage) {
*errorMessage = std::move(e);
} else {
@@ -3194,9 +3200,15 @@ cmsys::Status cmSystemTools::CreateLink(std::string const& origName,
uv_fs_link(nullptr, &req, origName.c_str(), newName.c_str(), nullptr);
cmsys::Status status;
if (err) {
+#if defined(_WIN32)
+ status = cmsys::Status::Windows(uv_fs_get_system_error(&req));
+#elif UV_VERSION_MAJOR > 1 || (UV_VERSION_MAJOR == 1 && UV_VERSION_MINOR >= 38)
+ status = cmsys::Status::POSIX(uv_fs_get_system_error(&req));
+#else
status = cmsys::Status::POSIX(-err);
+#endif
std::string e =
- "failed to create link '" + newName + "': " + uv_strerror(err);
+ cmStrCat("failed to create link '", newName, "': ", status.GetString());
if (errorMessage) {
*errorMessage = std::move(e);
} else {