From 1461ae49330595b7e7d59e793107dd809bb56720 Mon Sep 17 00:00:00 2001 From: John Parent Date: Thu, 22 Sep 2022 12:54:22 -0400 Subject: file(INSTALL): Clarify symlink vs dir conflict errors Clarify error reporting in scenario creating a symlink where a directory previously exists. --- Source/cmFileCopier.cxx | 17 ++++++++++++++++- .../install/DIRECTORY-symlink-clobber-all-stderr.txt | 2 +- 2 files changed, 17 insertions(+), 2 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 + # include "cmsys/FStream.hxx" +#else +# include #endif #include @@ -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; } diff --git a/Tests/RunCMake/install/DIRECTORY-symlink-clobber-all-stderr.txt b/Tests/RunCMake/install/DIRECTORY-symlink-clobber-all-stderr.txt index cdde3e0..d082b8a 100644 --- a/Tests/RunCMake/install/DIRECTORY-symlink-clobber-all-stderr.txt +++ b/Tests/RunCMake/install/DIRECTORY-symlink-clobber-all-stderr.txt @@ -9,4 +9,4 @@ [^ ]*/Tests/RunCMake/install/DIRECTORY-symlink-clobber-build/root-all/dest/dir - because: + because: A directory already exists at that location -- cgit v0.12