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 from __future__ import print_function | 8 from __future__ import print_function |
9 import errno | 9 import errno |
10 import logging | 10 import logging |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 self._fetch(rundir, verbose, depth) | 399 self._fetch(rundir, verbose, depth) |
400 except RefsHeadsFailedToFetch: | 400 except RefsHeadsFailedToFetch: |
401 # This is a major failure, we need to clean and force a bootstrap. | 401 # This is a major failure, we need to clean and force a bootstrap. |
402 gclient_utils.rmtree(rundir) | 402 gclient_utils.rmtree(rundir) |
403 self.print(GIT_CACHE_CORRUPT_MESSAGE) | 403 self.print(GIT_CACHE_CORRUPT_MESSAGE) |
404 tempdir = self._ensure_bootstrapped(depth, bootstrap, force=True) | 404 tempdir = self._ensure_bootstrapped(depth, bootstrap, force=True) |
405 assert tempdir | 405 assert tempdir |
406 self._fetch(tempdir or self.mirror_path, verbose, depth) | 406 self._fetch(tempdir or self.mirror_path, verbose, depth) |
407 finally: | 407 finally: |
408 if tempdir: | 408 if tempdir: |
409 os.rename(tempdir, self.mirror_path) | 409 try: |
| 410 os.rename(tempdir, self.mirror_path) |
| 411 except OSError as e: |
| 412 # This is somehow racy on Windows. |
| 413 # Catching OSError because WindowsError isn't portable and |
| 414 # pylint complains. |
| 415 self.print('Error moving %s to %s: %s' % (tempdir, self.mirror_path, |
| 416 str(e))) |
410 if not ignore_lock: | 417 if not ignore_lock: |
411 lockfile.unlock() | 418 lockfile.unlock() |
412 | 419 |
413 def update_bootstrap(self, prune=False): | 420 def update_bootstrap(self, prune=False): |
414 # The files are named <git number>.zip | 421 # The files are named <git number>.zip |
415 gen_number = subprocess.check_output( | 422 gen_number = subprocess.check_output( |
416 [self.git_exe, 'number', 'master'], cwd=self.mirror_path).strip() | 423 [self.git_exe, 'number', 'master'], cwd=self.mirror_path).strip() |
417 self.RunGit(['gc']) # Run Garbage Collect to compress packfile. | 424 self.RunGit(['gc']) # Run Garbage Collect to compress packfile. |
418 # Creating a temp file and then deleting it ensures we can use this name. | 425 # Creating a temp file and then deleting it ensures we can use this name. |
419 _, tmp_zipfile = tempfile.mkstemp(suffix='.zip') | 426 _, tmp_zipfile = tempfile.mkstemp(suffix='.zip') |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 return options, args | 631 return options, args |
625 | 632 |
626 | 633 |
627 def main(argv): | 634 def main(argv): |
628 dispatcher = subcommand.CommandDispatcher(__name__) | 635 dispatcher = subcommand.CommandDispatcher(__name__) |
629 return dispatcher.execute(OptionParser(), argv) | 636 return dispatcher.execute(OptionParser(), argv) |
630 | 637 |
631 | 638 |
632 if __name__ == '__main__': | 639 if __name__ == '__main__': |
633 sys.exit(main(sys.argv[1:])) | 640 sys.exit(main(sys.argv[1:])) |
OLD | NEW |