Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(998)

Unified Diff: git_cache.py

Issue 2497503002: Add retries to file operations for Windows. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cache.py
diff --git a/git_cache.py b/git_cache.py
index 0f66de72e9746b170df01982ccbf6ebaf0ac1936..88ba321d71b36355065b9a1f209cff1e834954bf 100755
--- a/git_cache.py
+++ b/git_cache.py
@@ -181,7 +181,7 @@ class Mirror(object):
else:
self.print = print
- def print_without_file(self, message, **kwargs):
+ def print_without_file(self, message, **_kwargs):
self.print_func(message)
@property
@@ -230,6 +230,23 @@ class Mirror(object):
setattr(cls, 'cachepath', cachepath)
return getattr(cls, 'cachepath')
+ def Rename(self, src, dst, count=3):
+ i = 0
+ while True:
+ i += 1
+
+ try:
+ os.rename(src, dst)
+ return
+ except OSError as e:
+ # This is somehow racy on Windows.
+ # Catching OSError because WindowsError isn't portable and
+ # pylint complains.
+ if i >= count:
+ raise
+ self.print('Error moving [%s] to [%s] (%d / %d): %s' % (
nodir 2016/11/11 01:34:30 attempt %d / %d so make it obviously clear
+ src, dst, i+1, count, str(e)))
nodir 2016/11/11 01:34:30 sleep?
nodir 2016/11/11 01:34:30 str unnecessary?
+
def RunGit(self, cmd, **kwargs):
"""Run git in a subprocess."""
cwd = kwargs.setdefault('cwd', self.mirror_path)
@@ -441,7 +458,7 @@ class Mirror(object):
if tempdir:
if os.path.exists(self.mirror_path):
gclient_utils.rmtree(self.mirror_path)
- os.rename(tempdir, self.mirror_path)
+ self.Rename(tempdir, self.mirror_path)
if not ignore_lock:
lockfile.unlock()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698