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() |