Be more aggressive about breaking locks
There is an issue where:
1. Lock for asdf.git acquires, which creates asdf.lock
2. asdf.git is cloned into tmp_asdf.git
3. Buildbot crashes, because timeouts
4. neither asdf.lock or tmp_asdf.git/config.lock gets cleaned out on the next unlock.
This aims to fix this issue by aggressively unlocking everything it can find that
vaguely resembles a lock.
BUG=339171
Review URL: https://codereview.chromium.org/187283005
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@255138 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/git_cache.py b/git_cache.py
index 6b430f8..f38b4e9 100755
--- a/git_cache.py
+++ b/git_cache.py
@@ -243,6 +243,14 @@
repo_dirs = [os.path.join(options.cache_dir, path)
for path in os.listdir(options.cache_dir)
if os.path.isdir(os.path.join(options.cache_dir, path))]
+ repo_dirs.extend([os.path.join(options.cache_dir,
+ lockfile.replace('.lock', ''))
+ for lockfile in os.listdir(options.cache_dir)
+ if os.path.isfile(os.path.join(options.cache_dir,
+ lockfile))
+ and lockfile.endswith('.lock')
+ and os.path.join(options.cache_dir, lockfile)
+ not in repo_dirs])
lockfiles = [repo_dir + '.lock' for repo_dir in repo_dirs
if os.path.exists(repo_dir + '.lock')]
@@ -255,11 +263,16 @@
untouched = []
for repo_dir in repo_dirs:
lf = Lockfile(repo_dir)
+ config_lock = os.path.join(repo_dir, 'config.lock')
+ unlocked = False
+ if os.path.exists(config_lock):
+ os.remove(config_lock)
+ unlocked = True
if lf.break_lock():
- config_lock = os.path.join(repo_dir, 'config.lock')
- if os.path.exists(config_lock):
- os.remove(config_lock)
- unlocked.append(repo_dir)
+ unlocked = True
+
+ if unlocked:
+ unlocked.append(repo_dir)
else:
untouched.append(repo_dir)