From 4e2ad84696a0c30a568103df78abf3b042dcbe86 Mon Sep 17 00:00:00 2001 From: "hinoka@chromium.org" Date: Sat, 19 Jul 2014 01:23:45 +0000 Subject: [PATCH] Git Cache speculative fix for windows Git cache sometimes fail on: Traceback (most recent call last): File "E:\b\depot_tools\\gclient.py", line 2064, in sys.exit(Main(sys.argv[1:])) File "E:\b\depot_tools\\gclient.py", line 2052, in Main return dispatcher.execute(OptionParser(), argv) File "E:\b\depot_tools\subcommand.py", line 245, in execute return command(parser, args[1:]) File "E:\b\depot_tools\\gclient.py", line 1830, in CMDsync ret = client.RunOnDeps('update', args) File "E:\b\depot_tools\\gclient.py", line 1342, in RunOnDeps work_queue.flush(revision_overrides, command, args, options=self._options) File "E:\b\depot_tools\gclient_utils.py", line 852, in flush self._run_one_task(self.queued.pop(i), args, kwargs) File "E:\b\depot_tools\gclient_utils.py", line 944, in _run_one_task task_item.run(*args, **kwargs) File "E:\b\depot_tools\\gclient.py", line 744, in run file_list) File "E:\b\depot_tools\gclient_scm.py", line 160, in RunCommand return getattr(self, command)(options, args, file_list) File "E:\b\depot_tools\gclient_scm.py", line 387, in update self._UpdateMirror(mirror, options) File "E:\b\depot_tools\gclient_scm.py", line 802, in _UpdateMirror ignore_lock=options.ignore_locks) File "E:\b\depot_tools\git_cache.py", line 409, in populate os.rename(tempdir, self.mirror_path) WindowsError: [Error 183] Cannot create a file when that file already exists It would appear that its being racy, but otherwise it doesn't make any sense. A theory is that this could be running twice and stepping on each other. Allowing this to pass on OSError allows us to test this theory. BUG=395333 Review URL: https://codereview.chromium.org/408653002 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@284272 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cache.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/git_cache.py b/git_cache.py index ae8a519487..59bd48cbc0 100755 --- a/git_cache.py +++ b/git_cache.py @@ -406,7 +406,14 @@ class Mirror(object): self._fetch(tempdir or self.mirror_path, verbose, depth) finally: if tempdir: - os.rename(tempdir, self.mirror_path) + try: + os.rename(tempdir, self.mirror_path) + except OSError as e: + # This is somehow racy on Windows. + # Catching OSError because WindowsError isn't portable and + # pylint complains. + self.print('Error moving %s to %s: %s' % (tempdir, self.mirror_path, + str(e))) if not ignore_lock: lockfile.unlock()