cmSystemTools::RenameFile: Retry on Windows ERROR_SHARING_VIOLATION

Add ERROR_SHARING_VIOLATION to the set of errors (previously including
only ERROR_ACCESS_DENIED) that cause a rename (MoveFile) on Windows to
retry.  The condition was observed when two renames to the same target
file name were happening simultaneously.
This commit is contained in:
Eric Berge 2014-05-13 09:10:38 -05:00 committed by Brad King
parent 9996b9846d
commit 24bd7ae11a
1 changed files with 4 additions and 2 deletions

View File

@ -917,8 +917,10 @@ bool cmSystemTools::RenameFile(const char* oldname, const char* newname)
cmsys::Encoding::ToWide(newname).c_str(),
MOVEFILE_REPLACE_EXISTING) && --retry.Count)
{
// Try again only if failure was due to access permissions.
if(GetLastError() != ERROR_ACCESS_DENIED)
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;
}