summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorJohn Parent <john.parent@kitware.com>2022-09-22 16:54:22 (GMT)
committerBrad King <brad.king@kitware.com>2022-10-06 19:10:05 (GMT)
commit1461ae49330595b7e7d59e793107dd809bb56720 (patch)
treee5bfc57b25676fed4f012eee3724aff7480a5aac /Source
parent85f01a1ec2203187d4cd99c74136774059b89b35 (diff)
downloadCMake-1461ae49330595b7e7d59e793107dd809bb56720.zip
CMake-1461ae49330595b7e7d59e793107dd809bb56720.tar.gz
CMake-1461ae49330595b7e7d59e793107dd809bb56720.tar.bz2
file(INSTALL): Clarify symlink vs dir conflict errors
Clarify error reporting in scenario creating a symlink where a directory previously exists.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmFileCopier.cxx17
1 files changed, 16 insertions, 1 deletions
diff --git a/Source/cmFileCopier.cxx b/Source/cmFileCopier.cxx
index 6ad7706..70e6089 100644
--- a/Source/cmFileCopier.cxx
+++ b/Source/cmFileCopier.cxx
@@ -15,7 +15,11 @@
#include "cmValue.h"
#ifdef _WIN32
+# include <winerror.h>
+
# include "cmsys/FStream.hxx"
+#else
+# include <cerrno>
#endif
#include <cstring>
@@ -561,9 +565,20 @@ bool cmFileCopier::InstallSymlink(const std::string& fromFile,
cmsys::Status status =
cmSystemTools::CreateSymlinkQuietly(symlinkTarget, toFile);
if (!status) {
+#ifdef _WIN32
+ bool const errorFileExists = status.GetWindows() == ERROR_FILE_EXISTS;
+#else
+ bool const errorFileExists = status.GetPOSIX() == EEXIST;
+#endif
+ std::string reason;
+ if (errorFileExists && cmSystemTools::FileIsDirectory(toFile)) {
+ reason = "A directory already exists at that location";
+ } else {
+ reason = status.GetString();
+ }
std::string e =
cmStrCat(this->Name, " cannot duplicate symlink\n ", fromFile,
- "\nat\n ", toFile, "\nbecause: ", status.GetString());
+ "\nat\n ", toFile, "\nbecause: ", reason);
this->Status.SetError(e);
return false;
}