mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-08 14:50:10 -06:00
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.
This commit is contained in:
@@ -644,7 +644,11 @@ macro (CMAKE_BUILD_UTILITIES)
|
||||
#---------------------------------------------------------------------
|
||||
# Build libuv library.
|
||||
if(CMAKE_USE_SYSTEM_LIBUV)
|
||||
find_package(LibUV 1.10.0)
|
||||
if(WIN32)
|
||||
find_package(LibUV 1.38.0)
|
||||
else()
|
||||
find_package(LibUV 1.10.0)
|
||||
endif()
|
||||
if(NOT LIBUV_FOUND)
|
||||
message(FATAL_ERROR
|
||||
"CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!")
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1 +1 @@
|
||||
^CMake Error: failed to create link .* no such file or directory
|
||||
^CMake Error: failed to create link '[^']+': [A-Za-z]
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
if(${actual_stderr_var} MATCHES "operation not permitted")
|
||||
if(${actual_stderr_var} MATCHES "A required privilege is not held by the client")
|
||||
unset(msg)
|
||||
endif()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if(${actual_stderr_var} MATCHES "operation not permitted")
|
||||
if(${actual_stderr_var} MATCHES "A required privilege is not held by the client")
|
||||
unset(msg)
|
||||
else()
|
||||
if(NOT IS_SYMLINK ${RunCMake_TEST_BINARY_DIR}/L)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if(${actual_stderr_var} MATCHES "operation not permitted")
|
||||
if(${actual_stderr_var} MATCHES "A required privilege is not held by the client")
|
||||
unset(msg)
|
||||
else()
|
||||
if(NOT IS_DIRECTORY ${RunCMake_TEST_BINARY_DIR}/L)
|
||||
|
||||
@@ -359,7 +359,7 @@ run_cmake_command(E_create_symlink-missing-dir
|
||||
# These tests are special on Windows since it will only fail if the user
|
||||
# running the test does not have the priveldge to create symlinks. If this
|
||||
# happens we clear the msg in the -check.cmake and say that the test passes
|
||||
set(RunCMake_DEFAULT_stderr "(operation not permitted)?")
|
||||
set(RunCMake_DEFAULT_stderr "(A required privilege is not held by the client)?")
|
||||
set(RunCMake_TEST_BINARY_DIR
|
||||
${RunCMake_BINARY_DIR}/E_create_symlink-broken-build)
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
@@ -403,7 +403,7 @@ run_cmake_command(E_create_hardlink-no-directory
|
||||
|
||||
#On Windows, if the user does not have sufficient privileges
|
||||
#don't fail this test
|
||||
set(RunCMake_DEFAULT_stderr "(operation not permitted)?")
|
||||
set(RunCMake_DEFAULT_stderr "(A required privilege is not held by the client)?")
|
||||
run_cmake_command(E_create_hardlink-unresolved-symlink-prereq
|
||||
${CMAKE_COMMAND} -E create_symlink ${dir}/1 ${dir}/1-symlink
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user