OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """A git command for managing a local cache of git repositories.""" | 6 """A git command for managing a local cache of git repositories.""" |
7 | 7 |
8 import errno | 8 import errno |
9 import logging | 9 import logging |
10 import optparse | 10 import optparse |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 if len(args) > 1 or (len(args) == 0 and not options.all): | 236 if len(args) > 1 or (len(args) == 0 and not options.all): |
237 parser.error('git cache unlock takes exactly one repo url, or --all') | 237 parser.error('git cache unlock takes exactly one repo url, or --all') |
238 | 238 |
239 if not options.all: | 239 if not options.all: |
240 url = args[0] | 240 url = args[0] |
241 repo_dirs = [os.path.join(options.cache_dir, UrlToCacheDir(url))] | 241 repo_dirs = [os.path.join(options.cache_dir, UrlToCacheDir(url))] |
242 else: | 242 else: |
243 repo_dirs = [os.path.join(options.cache_dir, path) | 243 repo_dirs = [os.path.join(options.cache_dir, path) |
244 for path in os.listdir(options.cache_dir) | 244 for path in os.listdir(options.cache_dir) |
245 if os.path.isdir(os.path.join(options.cache_dir, path))] | 245 if os.path.isdir(os.path.join(options.cache_dir, path))] |
| 246 repo_dirs.extend([os.path.join(options.cache_dir, |
| 247 lockfile.replace('.lock', '')) |
| 248 for lockfile in os.listdir(options.cache_dir) |
| 249 if os.path.isfile(os.path.join(options.cache_dir, |
| 250 lockfile)) |
| 251 and lockfile.endswith('.lock') |
| 252 and os.path.join(options.cache_dir, lockfile) |
| 253 not in repo_dirs]) |
246 lockfiles = [repo_dir + '.lock' for repo_dir in repo_dirs | 254 lockfiles = [repo_dir + '.lock' for repo_dir in repo_dirs |
247 if os.path.exists(repo_dir + '.lock')] | 255 if os.path.exists(repo_dir + '.lock')] |
248 | 256 |
249 if not options.force: | 257 if not options.force: |
250 parser.error('git cache unlock requires -f|--force to do anything. ' | 258 parser.error('git cache unlock requires -f|--force to do anything. ' |
251 'Refusing to unlock the following repo caches: ' | 259 'Refusing to unlock the following repo caches: ' |
252 ', '.join(lockfiles)) | 260 ', '.join(lockfiles)) |
253 | 261 |
254 unlocked = [] | 262 unlocked = [] |
255 untouched = [] | 263 untouched = [] |
256 for repo_dir in repo_dirs: | 264 for repo_dir in repo_dirs: |
257 lf = Lockfile(repo_dir) | 265 lf = Lockfile(repo_dir) |
| 266 config_lock = os.path.join(repo_dir, 'config.lock') |
| 267 unlocked = False |
| 268 if os.path.exists(config_lock): |
| 269 os.remove(config_lock) |
| 270 unlocked = True |
258 if lf.break_lock(): | 271 if lf.break_lock(): |
259 config_lock = os.path.join(repo_dir, 'config.lock') | 272 unlocked = True |
260 if os.path.exists(config_lock): | 273 |
261 os.remove(config_lock) | 274 if unlocked: |
262 unlocked.append(repo_dir) | 275 unlocked.append(repo_dir) |
263 else: | 276 else: |
264 untouched.append(repo_dir) | 277 untouched.append(repo_dir) |
265 | 278 |
266 if unlocked: | 279 if unlocked: |
267 logging.info('Broke locks on these caches: %s' % unlocked) | 280 logging.info('Broke locks on these caches: %s' % unlocked) |
268 if untouched: | 281 if untouched: |
269 logging.debug('Did not touch these caches: %s' % untouched) | 282 logging.debug('Did not touch these caches: %s' % untouched) |
270 | 283 |
271 | 284 |
272 class OptionParser(optparse.OptionParser): | 285 class OptionParser(optparse.OptionParser): |
(...skipping 28 matching lines...) Expand all Loading... |
301 return options, args | 314 return options, args |
302 | 315 |
303 | 316 |
304 def main(argv): | 317 def main(argv): |
305 dispatcher = subcommand.CommandDispatcher(__name__) | 318 dispatcher = subcommand.CommandDispatcher(__name__) |
306 return dispatcher.execute(OptionParser(), argv) | 319 return dispatcher.execute(OptionParser(), argv) |
307 | 320 |
308 | 321 |
309 if __name__ == '__main__': | 322 if __name__ == '__main__': |
310 sys.exit(main(sys.argv[1:])) | 323 sys.exit(main(sys.argv[1:])) |
OLD | NEW |