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 ca91dbdf98d15876634feeb65406ba9007608523..9cd4087a552fe0860093545b1376320ea787c1af 100755 |
--- a/recipe_modules/bot_update/resources/bot_update.py |
+++ b/recipe_modules/bot_update/resources/bot_update.py |
@@ -210,7 +210,6 @@ def call(*args, **kwargs): # pragma: no cover |
(' '.join(args), code, cwd, attempt), |
code, outval) |
- |
def git(*args, **kwargs): # pragma: no cover |
"""Wrapper around call specifically for Git commands.""" |
if args and args[0] == 'cache': |
@@ -222,9 +221,32 @@ def git(*args, **kwargs): # pragma: no cover |
# have to do it explicitly. This is better than passing shell=True. |
if sys.platform.startswith('win'): |
git_executable += '.bat' |
+ # Windows sometimes has trouble deleting files. This can make git commands |
+ # that rely on locks fail. |
+ remove_git_lockfiles(sys.platform, os.getcwd()) |
Paweł Hajdan Jr.
2016/10/07 13:47:43
Well this still runs before _each_ git command rat
katthomas
2016/10/07 18:49:16
Right, I was thinking that any git command could c
Paweł Hajdan Jr.
2016/10/10 14:58:04
That'd sound good to me.
agable
2016/10/10 23:01:34
Yep, I'm in agreement with Pawel here: breaking lo
katthomas
2016/10/11 17:29:18
Makes sense, done.
|
cmd = (git_executable,) + args |
return call(*cmd, **kwargs) |
+def remove_git_lockfiles(platform, cwd, retries=3): |
+ if not platform.startswith('win'): |
agable
2016/10/10 23:01:34
nit: It's a matter of opinion whether it is better
katthomas
2016/10/11 17:29:18
Thanks!
|
+ return |
+ git_dir = cwd + '/.git' |
agable
2016/10/10 23:01:34
Can you guarantee that all callers of this functio
katthomas
2016/10/11 17:29:18
Done.
|
+ try: |
+ lockfiles = [git_dir + '/' + f for f in os.listdir(git_dir) |
+ if f.endswith('.lock')] |
+ except Exception as e: |
+ print 'Could not remove git lockfiles: %s' % str(e) |
+ return |
+ if lockfiles: |
+ for filename in lockfiles: |
+ print '===Attempting to remove lockfile %s===' % filename |
agable
2016/10/10 23:01:34
super duper tiny nit: I'd print these big header/f
katthomas
2016/10/11 17:29:18
Done.
|
+ for _ in xrange(retries): |
+ exitcode = call('cmd.exe', '/c', 'del', |
+ '/f', '/q', os.path.normcase(filename)) |
+ if exitcode == 0: |
+ return |
+ time.sleep(3) |
+ print '===Failed to remove lockfile %s====' % filename |
def get_gclient_spec(solutions, target_os, target_os_only, git_cache_dir): |
return GCLIENT_TEMPLATE % { |