diff options
author | Brad King <brad.king@kitware.com> | 2021-04-14 16:20:00 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-04-14 17:14:29 (GMT) |
commit | 3ef5dab010aef5ebab2022021989cb80718d00fc (patch) | |
tree | 1b98c09504aa9ff4e527c453c22bfdf9bf46a307 /Source | |
parent | ec1b6157cbfefdcac5c971021a5700dd80318a09 (diff) | |
download | CMake-3ef5dab010aef5ebab2022021989cb80718d00fc.zip CMake-3ef5dab010aef5ebab2022021989cb80718d00fc.tar.gz CMake-3ef5dab010aef5ebab2022021989cb80718d00fc.tar.bz2 |
cmSystemTools: Simplify using KWSys Status
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmSystemTools.cxx | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index a2a406c..2b3266d 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -153,27 +153,6 @@ static int cm_archive_read_open_file(struct archive* a, const char* file, # define environ (*_NSGetEnviron()) #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_DisableRunCommandOutput = false; bool cmSystemTools::s_ErrorOccured = false; @@ -1023,16 +1002,24 @@ cmSystemTools::CopyResult cmSystemTools::CopySingleFile( 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 (!cmsys::SystemTools::CopyFileContentBlockwise(oldname, newname)) { - ReportError(err); - return CopyResult::Failure; + status = cmsys::SystemTools::CopyFileContentBlockwise(oldname, newname); + } + if (!status) { + if (err) { + *err = status.GetString(); } + return CopyResult::Failure; } if (perms) { - if (!SystemTools::SetPermissions(newname, perm)) { - ReportError(err); + status = SystemTools::SetPermissions(newname, perm); + if (!status) { + if (err) { + *err = status.GetString(); + } return CopyResult::Failure; } } @@ -1090,7 +1077,9 @@ cmSystemTools::RenameResult cmSystemTools::RenameFile( if (replace == Replace::No && move_last_error == ERROR_ALREADY_EXISTS) { return RenameResult::NoReplace; } - ReportError(err); + if (err) { + *err = cmsys::Status::Windows(move_last_error).GetString(); + } return RenameResult::Failure; } @@ -1121,7 +1110,9 @@ cmSystemTools::RenameResult cmSystemTools::RenameFile( if (replace == Replace::No && GetLastError() == ERROR_ALREADY_EXISTS) { return RenameResult::NoReplace; } - ReportError(err); + if (err) { + *err = cmsys::Status::Windows_GetLastError().GetString(); + } return RenameResult::Failure; #else // On UNIX we have OS-provided calls to create 'newname' atomically. @@ -1132,13 +1123,17 @@ cmSystemTools::RenameResult cmSystemTools::RenameFile( if (errno == EEXIST) { return RenameResult::NoReplace; } - ReportError(err); + if (err) { + *err = cmsys::Status::POSIX_errno().GetString(); + } return RenameResult::Failure; } if (rename(oldname.c_str(), newname.c_str()) == 0) { return RenameResult::Success; } - ReportError(err); + if (err) { + *err = cmsys::Status::POSIX_errno().GetString(); + } return RenameResult::Failure; #endif } |