From 19d50ee2c29c4f43b5fdaae40fa37e996ea39655 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 16 Nov 2023 12:45:48 -0500 Subject: [PATCH] Meta: Extract .zip file directories in an encoding-agnostic manner The current implementation fails if a file in the archive is not valid UTF-8. The CLDR 44.0.1 package unfortunately contains such files (it errantly has .DS_Store files). --- Meta/gn/build/extract_archive_contents.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Meta/gn/build/extract_archive_contents.py b/Meta/gn/build/extract_archive_contents.py index 10b5b930f2..54cc23992d 100644 --- a/Meta/gn/build/extract_archive_contents.py +++ b/Meta/gn/build/extract_archive_contents.py @@ -47,15 +47,11 @@ def extract_directory(file, destination, path): destination_path.mkdir(parents=True, exist_ok=True) if not isinstance(file, zipfile.ZipFile): raise NotImplementedError + # FIXME: This loops over the entire archive len(args.paths) times. Decrease complexity for entry in file.namelist(): if entry.startswith(path): - entry_destination = destination / entry - if entry.endswith('/'): - entry_destination.mkdir(exist_ok=True) - continue - with file.open(entry) as member: - entry_destination.write_text(member.read().decode('utf-8')) + file.extract(entry, destination) def main():