Index: git_cache.py |
diff --git a/git_cache.py b/git_cache.py |
index 0f66de72e9746b170df01982ccbf6ebaf0ac1936..9054db8713a23ed111660be8dfaab8476da85ff1 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,26 @@ class Mirror(object): |
setattr(cls, 'cachepath', cachepath) |
return getattr(cls, 'cachepath') |
+ def Rename(self, src, dst, count=3): |
+ sleep_time = 1 |
nodir
2016/11/11 01:53:59
Strange indentation
|
+ while True: |
+ 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 not count: |
+ raise |
+ |
+ self.print('Error moving [%s] to [%s] (%d retries remaining): %s' % ( |
+ src, dst, count, str(e))) |
nodir
2016/11/11 01:53:59
str unnecessary?
|
+ time.sleep(sleep_time) |
+ count -= 1 |
+ sleep_time *= 2 |
+ |
+ |
def RunGit(self, cmd, **kwargs): |
"""Run git in a subprocess.""" |
cwd = kwargs.setdefault('cwd', self.mirror_path) |
@@ -441,7 +461,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() |