Skip to content

Commit

Permalink
Make zap_downloadl.py create a usable zap.app on Mac (#35242)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ksperling-apple authored and pull[bot] committed Dec 11, 2024
1 parent cf70e9b commit 3790590
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions scripts/tools/zap/zap_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import shutil
import subprocess
import sys
import tempfile
import zipfile
from typing import Optional

Expand Down Expand Up @@ -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.")


Expand Down

0 comments on commit 3790590

Please sign in to comment.