From 3c8161f9877644eb0b7f356769e8f6e8ee47ada5 Mon Sep 17 00:00:00 2001
From: Eric Berge <ericmberge@gmail.com>
Date: Tue, 13 May 2014 09:10:38 -0500
Subject: [PATCH 3/3] Retry rename on Windows ERROR_SHARING_VIOLATION

---
 Source/cmSystemTools.cxx | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index c27b561..c38a99c 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -886,8 +886,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;
       }
-- 
1.8.2.1

