From b54190a406327e7ebcba62dd90fe03a55dbb6c26 Mon Sep 17 00:00:00 2001 From: Ron W Moore Date: Tue, 25 Aug 2020 21:22:52 -0400 Subject: cmSystemTools: Teach RenameFile to try for longer on directories Issue: #19580 --- Source/cmSystemTools.cxx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 95944a2..69acf92 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -809,6 +809,17 @@ WindowsFileRetryInit InitWindowsDirectoryRetry() return dirInit; } +cmSystemTools::WindowsFileRetry GetWindowsRetry(std::wstring const& path) +{ + // If we are performing a directory operation, then try and get the + // appropriate timing info. + DWORD const attrs = GetFileAttributesW(path.c_str()); + if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) { + return cmSystemTools::GetWindowsDirectoryRetry(); + } + return cmSystemTools::GetWindowsFileRetry(); +} + } // end of anonymous namespace cmSystemTools::WindowsFileRetry cmSystemTools::GetWindowsFileRetry() @@ -912,7 +923,7 @@ bool cmSystemTools::RenameFile(const std::string& oldname, 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(); + WindowsFileRetry retry = GetWindowsRetry(oldname_wstr); DWORD move_last_error = 0; while (!cmMoveFile(oldname_wstr, newname_wstr) && --retry.Count) { move_last_error = GetLastError(); -- cgit v0.12