diff --git a/swh/core/tarball.py b/swh/core/tarball.py --- a/swh/core/tarball.py +++ b/swh/core/tarball.py @@ -22,12 +22,11 @@ This expects the `extract_dir` to exist. - Raises - + Raises: shutil.ReadError in case of issue uncompressing the archive (tarpath does not exist, extract_dir does not exist, etc...) - Returns + Returns: full path to the uncompressed directory. """ @@ -40,6 +39,29 @@ ) +def _unpack_zip(zippath: str, extract_dir: str) -> str: + """Unpack zip files unsupported by the standard python library, for instance + those with legacy compression type 6 (implode). + + This expects the `extract_dir` to exist. + + Raises: + shutil.ReadError in case of issue uncompressing the archive (zippath + does not exist, extract_dir does not exist, etc...) + + Returns: + full path to the uncompressed directory. + + """ + try: + run(["unzip", "-d", extract_dir, zippath], check=True) + return extract_dir + except Exception as e: + raise shutil.ReadError( + f"Unable to uncompress {zippath} to {extract_dir}. Reason: {e}" + ) + + def register_new_archive_formats(): """Register new archive formats to uncompress @@ -72,6 +94,11 @@ shutil.unpack_archive(tarpath, extract_dir=dest) except shutil.ReadError as e: raise ValueError(f"Problem during unpacking {tarpath}. Reason: {e}") + except NotImplementedError: + if tarpath.endswith(".zip"): + return _unpack_zip(tarpath, dest) + else: + raise normalize_permissions(dest) diff --git a/swh/core/tests/data/archives/msk316src.zip b/swh/core/tests/data/archives/msk316src.zip new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ 0