From 1631e3b73d849796b35f60c93ac146aa9881d791 Mon Sep 17 00:00:00 2001 From: Karsten Sperling <113487422+ksperling-apple@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:24:02 +1200 Subject: [PATCH] Make zap_downloadl.py create a usable zap.app on Mac (#35242) Use the unzip utility on Mac for unzipping instead of zipfile. In addition to not supporting file modes (which the script already works around) the zipfile module also doesn't support symlinks. The embedded frameworks inside zap.app rely on symlinks for the application to work. --- scripts/tools/zap/zap_download.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/scripts/tools/zap/zap_download.py b/scripts/tools/zap/zap_download.py index 72dea27048a0c6..9d1a553feac0e8 100755 --- a/scripts/tools/zap/zap_download.py +++ b/scripts/tools/zap/zap_download.py @@ -23,6 +23,7 @@ import shutil import subprocess import sys +import tempfile import zipfile from typing import Optional @@ -123,13 +124,22 @@ def _SetupReleaseZap(install_directory: str, zap_version: str): logging.info("Fetching: %s", url) r = requests.get(url, stream=True) - z = zipfile.ZipFile(io.BytesIO(r.content)) - - logging.info("Data downloaded, extracting ...") - # extractall() does not preserve permissions (https://github.com/python/cpython/issues/59999) - for entry in z.filelist: - path = z.extract(entry, install_directory) - os.chmod(path, (entry.external_attr >> 16) & 0o777) + if zap_platform == 'mac': + # zipfile does not support symlinks (https://github.com/python/cpython/issues/82102), + # making a zap.app extracted with it unusable due to embedded frameworks. + with tempfile.NamedTemporaryFile(suffix='.zip') as tf: + for chunk in r.iter_content(chunk_size=4096): + tf.write(chunk) + tf.flush() + os.makedirs(install_directory, exist_ok=True) + _ExecuteProcess(['/usr/bin/unzip', '-oq', tf.name], install_directory) + else: + z = zipfile.ZipFile(io.BytesIO(r.content)) + logging.info("Data downloaded, extracting ...") + # extractall() does not preserve permissions (https://github.com/python/cpython/issues/59999) + for entry in z.filelist: + path = z.extract(entry, install_directory) + os.chmod(path, (entry.external_attr >> 16) & 0o777) logging.info("Done extracting.")