summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorRon W Moore <webbtrail@gmail.com>2020-08-25 13:44:56 (GMT)
committerBrad King <brad.king@kitware.com>2020-08-31 17:03:36 (GMT)
commit73f8240ae7594121704a8aa43d7ef25e8ffd2f75 (patch)
tree4582ebd52b250f92a5b19b13d813e3596030eb78 /Source/cmSystemTools.cxx
parent97fc44f70e2c97799d1b802289f220efd055be20 (diff)
downloadCMake-73f8240ae7594121704a8aa43d7ef25e8ffd2f75.zip
CMake-73f8240ae7594121704a8aa43d7ef25e8ffd2f75.tar.gz
CMake-73f8240ae7594121704a8aa43d7ef25e8ffd2f75.tar.bz2
cmSystemTools: Factor out RenameFile wstring conversion on Windows
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx17
1 files changed, 9 insertions, 8 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index a9785db..b63c318 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -898,28 +898,29 @@ bool cmSystemTools::RenameFile(const std::string& oldname,
# ifndef INVALID_FILE_ATTRIBUTES
# define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
# endif
+ std::wstring const oldname_wstr =
+ SystemTools::ConvertToWindowsExtendedPath(oldname);
+ std::wstring const newname_wstr =
+ SystemTools::ConvertToWindowsExtendedPath(newname);
+
/* Windows MoveFileEx may not replace read-only or in-use files. If it
fails then remove the read-only attribute from any existing destination.
Try multiple times since we may be racing against another process
creating/opening the destination file just before our MoveFileEx. */
WindowsFileRetry retry = cmSystemTools::GetWindowsFileRetry();
- while (!cmMoveFile(SystemTools::ConvertToWindowsExtendedPath(oldname),
- SystemTools::ConvertToWindowsExtendedPath(newname)) &&
- --retry.Count) {
+ while (!cmMoveFile(oldname_wstr, newname_wstr) && --retry.Count) {
DWORD last_error = GetLastError();
// Try again only if failure was due to access/sharing permissions.
if (last_error != ERROR_ACCESS_DENIED &&
last_error != ERROR_SHARING_VIOLATION) {
return false;
}
- DWORD attrs = GetFileAttributesW(
- SystemTools::ConvertToWindowsExtendedPath(newname).c_str());
+ DWORD const attrs = GetFileAttributesW(newname_wstr.c_str());
if ((attrs != INVALID_FILE_ATTRIBUTES) &&
(attrs & FILE_ATTRIBUTE_READONLY)) {
// Remove the read-only attribute from the destination file.
- SetFileAttributesW(
- SystemTools::ConvertToWindowsExtendedPath(newname).c_str(),
- attrs & ~FILE_ATTRIBUTE_READONLY);
+ SetFileAttributesW(newname_wstr.c_str(),
+ attrs & ~FILE_ATTRIBUTE_READONLY);
} else {
// The file may be temporarily in use so wait a bit.
cmSystemTools::Delay(retry.Delay);