mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-08 08:40:48 +00:00
cmSystemTools: Simplify using KWSys Status
This commit is contained in:
@@ -153,27 +153,6 @@ static int cm_archive_read_open_file(struct archive* a, const char* file,
|
|||||||
# define environ (*_NSGetEnviron())
|
# define environ (*_NSGetEnviron())
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
|
||||||
void ReportError(std::string* err)
|
|
||||||
{
|
|
||||||
if (!err) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#ifdef _WIN32
|
|
||||||
LPSTR message = NULL;
|
|
||||||
DWORD size = FormatMessageA(
|
|
||||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
|
||||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
||||||
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
||||||
(LPSTR)&message, 0, NULL);
|
|
||||||
*err = std::string(message, size);
|
|
||||||
LocalFree(message);
|
|
||||||
#else
|
|
||||||
*err = strerror(errno);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cmSystemTools::s_RunCommandHideConsole = false;
|
bool cmSystemTools::s_RunCommandHideConsole = false;
|
||||||
bool cmSystemTools::s_DisableRunCommandOutput = false;
|
bool cmSystemTools::s_DisableRunCommandOutput = false;
|
||||||
bool cmSystemTools::s_ErrorOccured = false;
|
bool cmSystemTools::s_ErrorOccured = false;
|
||||||
@@ -1023,16 +1002,24 @@ cmSystemTools::CopyResult cmSystemTools::CopySingleFile(
|
|||||||
return CopyResult::Success;
|
return CopyResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cmsys::SystemTools::CloneFileContent(oldname, newname)) {
|
cmsys::Status status;
|
||||||
|
status = cmsys::SystemTools::CloneFileContent(oldname, newname);
|
||||||
|
if (!status) {
|
||||||
// if cloning did not succeed, fall back to blockwise copy
|
// if cloning did not succeed, fall back to blockwise copy
|
||||||
if (!cmsys::SystemTools::CopyFileContentBlockwise(oldname, newname)) {
|
status = cmsys::SystemTools::CopyFileContentBlockwise(oldname, newname);
|
||||||
ReportError(err);
|
}
|
||||||
return CopyResult::Failure;
|
if (!status) {
|
||||||
|
if (err) {
|
||||||
|
*err = status.GetString();
|
||||||
}
|
}
|
||||||
|
return CopyResult::Failure;
|
||||||
}
|
}
|
||||||
if (perms) {
|
if (perms) {
|
||||||
if (!SystemTools::SetPermissions(newname, perm)) {
|
status = SystemTools::SetPermissions(newname, perm);
|
||||||
ReportError(err);
|
if (!status) {
|
||||||
|
if (err) {
|
||||||
|
*err = status.GetString();
|
||||||
|
}
|
||||||
return CopyResult::Failure;
|
return CopyResult::Failure;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1090,7 +1077,9 @@ cmSystemTools::RenameResult cmSystemTools::RenameFile(
|
|||||||
if (replace == Replace::No && move_last_error == ERROR_ALREADY_EXISTS) {
|
if (replace == Replace::No && move_last_error == ERROR_ALREADY_EXISTS) {
|
||||||
return RenameResult::NoReplace;
|
return RenameResult::NoReplace;
|
||||||
}
|
}
|
||||||
ReportError(err);
|
if (err) {
|
||||||
|
*err = cmsys::Status::Windows(move_last_error).GetString();
|
||||||
|
}
|
||||||
return RenameResult::Failure;
|
return RenameResult::Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1121,7 +1110,9 @@ cmSystemTools::RenameResult cmSystemTools::RenameFile(
|
|||||||
if (replace == Replace::No && GetLastError() == ERROR_ALREADY_EXISTS) {
|
if (replace == Replace::No && GetLastError() == ERROR_ALREADY_EXISTS) {
|
||||||
return RenameResult::NoReplace;
|
return RenameResult::NoReplace;
|
||||||
}
|
}
|
||||||
ReportError(err);
|
if (err) {
|
||||||
|
*err = cmsys::Status::Windows_GetLastError().GetString();
|
||||||
|
}
|
||||||
return RenameResult::Failure;
|
return RenameResult::Failure;
|
||||||
#else
|
#else
|
||||||
// On UNIX we have OS-provided calls to create 'newname' atomically.
|
// On UNIX we have OS-provided calls to create 'newname' atomically.
|
||||||
@@ -1132,13 +1123,17 @@ cmSystemTools::RenameResult cmSystemTools::RenameFile(
|
|||||||
if (errno == EEXIST) {
|
if (errno == EEXIST) {
|
||||||
return RenameResult::NoReplace;
|
return RenameResult::NoReplace;
|
||||||
}
|
}
|
||||||
ReportError(err);
|
if (err) {
|
||||||
|
*err = cmsys::Status::POSIX_errno().GetString();
|
||||||
|
}
|
||||||
return RenameResult::Failure;
|
return RenameResult::Failure;
|
||||||
}
|
}
|
||||||
if (rename(oldname.c_str(), newname.c_str()) == 0) {
|
if (rename(oldname.c_str(), newname.c_str()) == 0) {
|
||||||
return RenameResult::Success;
|
return RenameResult::Success;
|
||||||
}
|
}
|
||||||
ReportError(err);
|
if (err) {
|
||||||
|
*err = cmsys::Status::POSIX_errno().GetString();
|
||||||
|
}
|
||||||
return RenameResult::Failure;
|
return RenameResult::Failure;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user