From 776a2c3fc70c2c37d4d307fdb2230a2763608264 Mon Sep 17 00:00:00 2001 From: "hinoka@google.com" Date: Fri, 25 Apr 2014 07:54:25 +0000 Subject: [PATCH] Python fallback for git cache bootstrap This is because the version of unzip on osx doesn't support zip64, so it can't unzip large repositories like blink. BUG=261741 Review URL: https://codereview.chromium.org/251413002 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@266151 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cache.py | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/git_cache.py b/git_cache.py index 5c1f85a46e..52e42c5927 100755 --- a/git_cache.py +++ b/git_cache.py @@ -15,6 +15,7 @@ import time import subprocess import sys import urlparse +import zipfile from download_from_google_storage import Gsutil import gclient_utils @@ -222,26 +223,16 @@ class Mirror(object): self.RunGit(['config', '--add', 'remote.origin.fetch', refspec], cwd=cwd) def bootstrap_repo(self, directory): - """Bootstrap the repo from Google Stroage if possible. + """Bootstrap the repo from Google Stroage if possible.""" - Requires 7z on Windows and Unzip on Linux/Mac. - """ - if sys.platform.startswith('win'): - if not self.FindExecutable('7z'): - self.print(''' -Cannot find 7z in the path. If you want git cache to be able to bootstrap from -Google Storage, please install 7z from: - -http://www.7-zip.org/download.html -''') - return False - else: - if not self.FindExecutable('unzip'): - self.print(''' -Cannot find unzip in the path. If you want git cache to be able to bootstrap -from Google Storage, please ensure unzip is present on your system. -''') - return False + python_fallback = False + if sys.platform.startswith('win') and not self.FindExecutable('7z'): + python_fallback = True + elif sys.platform.startswith('darwin'): + # The OSX version of unzip doesn't support zip64. + python_fallback = True + elif not self.FindExecutable('unzip'): + python_fallback = True gs_folder = 'gs://%s/%s' % (self.bootstrap_bucket, self.basedir) gsutil = Gsutil( @@ -264,12 +255,23 @@ from Google Storage, please ensure unzip is present on your system. return False filename = os.path.join(tempdir, latest_checkout.split('/')[-1]) - # Unpack the file with 7z on Windows, or unzip everywhere else. - if sys.platform.startswith('win'): - cmd = ['7z', 'x', '-o%s' % directory, '-tzip', filename] + # Unpack the file with 7z on Windows, unzip on linux, or fallback. + if not python_fallback: + if sys.platform.startswith('win'): + cmd = ['7z', 'x', '-o%s' % directory, '-tzip', filename] + else: + cmd = ['unzip', filename, '-d', directory] + retcode = subprocess.call(cmd) else: - cmd = ['unzip', filename, '-d', directory] - retcode = subprocess.call(cmd) + try: + with zipfile.ZipFile(filename, 'r') as f: + f.printdir() + f.extractall(directory) + except Exception as e: + self.print('Encountered error: %s' % str(e), file=sys.stderr) + retcode = 1 + else: + retcode = 0 finally: # Clean up the downloaded zipfile. gclient_utils.rmtree(tempdir)