mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-21 23:00:50 +08:00
cmSystemTools: Factor out MoveFileExW call in RenameFile
This commit is contained in:
@@ -881,6 +881,16 @@ void cmSystemTools::InitializeLibUV()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
namespace {
|
||||||
|
bool cmMoveFile(std::wstring const& oldname, std::wstring const& newname)
|
||||||
|
{
|
||||||
|
return MoveFileExW(oldname.c_str(), newname.c_str(),
|
||||||
|
MOVEFILE_REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool cmSystemTools::RenameFile(const std::string& oldname,
|
bool cmSystemTools::RenameFile(const std::string& oldname,
|
||||||
const std::string& newname)
|
const std::string& newname)
|
||||||
{
|
{
|
||||||
@@ -893,10 +903,8 @@ bool cmSystemTools::RenameFile(const std::string& oldname,
|
|||||||
Try multiple times since we may be racing against another process
|
Try multiple times since we may be racing against another process
|
||||||
creating/opening the destination file just before our MoveFileEx. */
|
creating/opening the destination file just before our MoveFileEx. */
|
||||||
WindowsFileRetry retry = cmSystemTools::GetWindowsFileRetry();
|
WindowsFileRetry retry = cmSystemTools::GetWindowsFileRetry();
|
||||||
while (
|
while (!cmMoveFile(SystemTools::ConvertToWindowsExtendedPath(oldname),
|
||||||
!MoveFileExW(SystemTools::ConvertToWindowsExtendedPath(oldname).c_str(),
|
SystemTools::ConvertToWindowsExtendedPath(newname)) &&
|
||||||
SystemTools::ConvertToWindowsExtendedPath(newname).c_str(),
|
|
||||||
MOVEFILE_REPLACE_EXISTING) &&
|
|
||||||
--retry.Count) {
|
--retry.Count) {
|
||||||
DWORD last_error = GetLastError();
|
DWORD last_error = GetLastError();
|
||||||
// Try again only if failure was due to access/sharing permissions.
|
// Try again only if failure was due to access/sharing permissions.
|
||||||
|
Reference in New Issue
Block a user