file(INSTALL): Clarify symlink vs dir conflict errors

Clarify error reporting in scenario creating a symlink where a directory
previously exists.
This commit is contained in:
John Parent 2022-09-22 12:54:22 -04:00 committed by Brad King
parent 85f01a1ec2
commit 1461ae4933
2 changed files with 17 additions and 2 deletions

View File

@ -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;
}

View File

@ -9,4 +9,4 @@
[^
]*/Tests/RunCMake/install/DIRECTORY-symlink-clobber-build/root-all/dest/dir
because:
because: A directory already exists at that location