From f445997221e9f9dbae0cc9ac58578e620a9cd8be Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Thu, 23 Nov 2023 14:19:36 +0100 Subject: [PATCH] Fix extracting of several archives. - Archive already existing must not stop download of other archives. - Use copytree instead of rename to use second archive as patch on existing directory. (No need to remove tmpdir, as it is a temporary directory) --- kiwixbuild/dependencies/base.py | 13 +++++++++++-- kiwixbuild/utils.py | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/kiwixbuild/dependencies/base.py b/kiwixbuild/dependencies/base.py index dbe5ef2..a527478 100644 --- a/kiwixbuild/dependencies/base.py +++ b/kiwixbuild/dependencies/base.py @@ -131,8 +131,17 @@ class ReleaseDownload(Source): def _download(self, context): context.try_skip(neutralEnv("archive_dir"), self.full_name) - for archive in self.archives: - neutralEnv("download")(archive) + archive_iter = iter(self.archives) + archive = next(archive_iter, None) + while archive: + try: + neutralEnv("download")(archive) + except SkipCommand as e: + archive = next(archive_iter, None) + if not archive: + raise e + continue + archive = next(archive_iter, None) def _extract(self, context): context.try_skip(self.extract_path) diff --git a/kiwixbuild/utils.py b/kiwixbuild/utils.py index 8cce351..3d4f4f5 100644 --- a/kiwixbuild/utils.py +++ b/kiwixbuild/utils.py @@ -275,7 +275,7 @@ def extract_archive(archive_path, dest_dir, topdir=None, name=None): perm = (member.external_attr >> 16) & 0x1FF os.chmod(pj(tmpdir, getname(member)), perm) name = name or topdir - os.rename(pj(tmpdir, topdir), pj(dest_dir, name)) + shutil.copytree(pj(tmpdir, topdir), pj(dest_dir, name), symlinks=True, dirs_exist_ok=True) else: if name: dest_dir = pj(dest_dir, name)