summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2023-12-02 03:18:20 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2023-12-02 03:58:05 (GMT)
commit5cf7018af6a5f5f0c84c9b7d5b31d9f849503886 (patch)
tree9f7680a9ed2a1763d0464aeb10b27f910b0db21f /Source
parent0639a32d3a27b9a89b82d915f58cfd59a634bb44 (diff)
downloadCMake-5cf7018af6a5f5f0c84c9b7d5b31d9f849503886.zip
CMake-5cf7018af6a5f5f0c84c9b7d5b31d9f849503886.tar.gz
CMake-5cf7018af6a5f5f0c84c9b7d5b31d9f849503886.tar.bz2
cmFileCopier: remember error statuses and get their strings
The last error may have changed between the original call and the `GetLastSystemError()` call. Remember the status explicitly and ask it for its error string. Reported on Discourse: https://discourse.cmake.org/t/9539
Diffstat (limited to 'Source')
-rw-r--r--Source/cmFileCopier.cxx37
1 files changed, 23 insertions, 14 deletions
diff --git a/Source/cmFileCopier.cxx b/Source/cmFileCopier.cxx
index 663bddc..d6e91fa 100644
--- a/Source/cmFileCopier.cxx
+++ b/Source/cmFileCopier.cxx
@@ -86,10 +86,11 @@ bool cmFileCopier::SetPermissions(const std::string& toFile,
}
#endif
- if (!cmSystemTools::SetPermissions(toFile, permissions)) {
+ auto perm_status = cmSystemTools::SetPermissions(toFile, permissions);
+ if (!perm_status) {
std::ostringstream e;
e << this->Name << " cannot set permissions on \"" << toFile
- << "\": " << cmSystemTools::GetLastSystemError() << ".";
+ << "\": " << perm_status.GetString() << ".";
this->Status.SetError(e.str());
return false;
}
@@ -530,11 +531,13 @@ bool cmFileCopier::InstallSymlink(const std::string& fromFile,
{
// Read the original symlink.
std::string symlinkTarget;
- if (!cmSystemTools::ReadSymlink(fromFile, symlinkTarget)) {
+ auto read_symlink_status =
+ cmSystemTools::ReadSymlink(fromFile, symlinkTarget);
+ if (!read_symlink_status) {
std::ostringstream e;
e << this->Name << " cannot read symlink \"" << fromFile
<< "\" to duplicate at \"" << toFile
- << "\": " << cmSystemTools::GetLastSystemError() << ".";
+ << "\": " << read_symlink_status.GetString() << ".";
this->Status.SetError(e.str());
return false;
}
@@ -604,12 +607,15 @@ bool cmFileCopier::InstallFile(const std::string& fromFile,
this->ReportCopy(toFile, TypeFile, copy);
// Copy the file.
- if (copy && !cmSystemTools::CopyAFile(fromFile, toFile, true)) {
- std::ostringstream e;
- e << this->Name << " cannot copy file \"" << fromFile << "\" to \""
- << toFile << "\": " << cmSystemTools::GetLastSystemError() << ".";
- this->Status.SetError(e.str());
- return false;
+ if (copy) {
+ auto copy_status = cmSystemTools::CopyAFile(fromFile, toFile, true);
+ if (!copy_status) {
+ std::ostringstream e;
+ e << this->Name << " cannot copy file \"" << fromFile << "\" to \""
+ << toFile << "\": " << copy_status.GetString() << ".";
+ this->Status.SetError(e.str());
+ return false;
+ }
}
// Set the file modification time of the destination file.
@@ -620,10 +626,11 @@ bool cmFileCopier::InstallFile(const std::string& fromFile,
if (cmSystemTools::GetPermissions(toFile, perm)) {
cmSystemTools::SetPermissions(toFile, perm | mode_owner_write);
}
- if (!cmFileTimes::Copy(fromFile, toFile)) {
+ auto copy_status = cmFileTimes::Copy(fromFile, toFile);
+ if (!copy_status) {
std::ostringstream e;
e << this->Name << " cannot set modification time on \"" << toFile
- << "\": " << cmSystemTools::GetLastSystemError() << ".";
+ << "\": " << copy_status.GetString() << ".";
this->Status.SetError(e.str());
return false;
}
@@ -660,10 +667,12 @@ bool cmFileCopier::InstallDirectory(const std::string& source,
}
// Make sure the destination directory exists.
- if (!cmSystemTools::MakeDirectory(destination, default_dir_mode)) {
+ auto makedir_status =
+ cmSystemTools::MakeDirectory(destination, default_dir_mode);
+ if (!makedir_status) {
std::ostringstream e;
e << this->Name << " cannot make directory \"" << destination
- << "\": " << cmSystemTools::GetLastSystemError() << ".";
+ << "\": " << makedir_status.GetString() << ".";
this->Status.SetError(e.str());
return false;
}