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

Unified Diff: git_cache.py

Issue 2497503002: Add retries to file operations for Windows. (Closed)
Patch Set: Bug 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..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()
« 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