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

Unified Diff: recipe_modules/bot_update/resources/bot_update.py

Issue 2454463002: Make bot_update on win more resilient (Closed)
Patch Set: Make bot_update on win more resilient Created 4 years, 2 months 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 | tests/bot_update_coverage_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipe_modules/bot_update/resources/bot_update.py
diff --git a/recipe_modules/bot_update/resources/bot_update.py b/recipe_modules/bot_update/resources/bot_update.py
index 3211369667372e4ec45a6b52343120b69985a912..2fc8a1504decdbbe33cdfbd52782276687e60c48 100755
--- a/recipe_modules/bot_update/resources/bot_update.py
+++ b/recipe_modules/bot_update/resources/bot_update.py
@@ -465,6 +465,25 @@ def is_broken_repo_dir(repo_dir):
return not path.exists(os.path.join(repo_dir, '.git', 'config'))
+def _maybe_break_locks(checkout_path):
+ """This removes all .lock files from this repo's .git directory.
+
+ In particular, this will cleanup index.lock files, as well as ref lock
+ files.
+ """
+ git_dir = os.path.join(checkout_path, '.git')
+ for dirpath, _, filenames in os.walk(git_dir):
+ for filename in filenames:
+ if filename.endswith('.lock'):
+ to_break = os.path.join(dirpath, filename)
+ print 'breaking lock: %s' % to_break
+ try:
+ os.remove(to_break)
+ except OSError as ex:
+ print 'FAILED to break lock: %s: %s' % (to_break, ex)
+ raise
+
+
def git_checkout(solutions, revisions, shallow, refs, git_cache_dir):
build_dir = os.getcwd()
# Before we do anything, break all git_cache locks.
@@ -518,6 +537,18 @@ def git_checkout(solutions, revisions, shallow, refs, git_cache_dir):
refspec = '%s:%s' % (ref, ref.lstrip('+'))
git('fetch', 'origin', refspec, cwd=sln_dir)
+ # Windows sometimes has trouble deleting files.
+ # This can make git commands that rely on locks fail.
+ # Try a few times in case Windows has trouble again (and again).
+ if sys.platform.startswith('win'):
+ tries = 3
+ while tries:
+ try:
+ _maybe_break_locks(sln_dir)
+ break
+ except Exception:
+ tries -= 1
+
revision = get_target_revision(name, url, revisions) or 'HEAD'
force_revision(sln_dir, revision)
done = True
« no previous file with comments | « no previous file | tests/bot_update_coverage_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698