diff --git a/swh/core/tarball.py b/swh/core/tarball.py --- a/swh/core/tarball.py +++ b/swh/core/tarball.py @@ -90,11 +90,16 @@ """ try: os.makedirs(dest, exist_ok=True) - shutil.unpack_archive(tarpath, extract_dir=dest) + format = None + for format_, exts, _ in shutil.get_unpack_formats(): + if any([tarpath.lower().endswith(ext.lower()) for ext in exts]): + format = format_ + break + shutil.unpack_archive(tarpath, extract_dir=dest, format=format) except shutil.ReadError as e: raise ValueError(f"Problem during unpacking {tarpath}. Reason: {e}") except NotImplementedError: - if tarpath.endswith(".zip"): + if tarpath.lower().endswith(".zip"): _unpack_zip(tarpath, dest) else: raise diff --git a/swh/core/tests/test_tarball.py b/swh/core/tests/test_tarball.py --- a/swh/core/tests/test_tarball.py +++ b/swh/core/tests/test_tarball.py @@ -222,3 +222,21 @@ tarball.uncompress(zippath, extract_dir) assert len(os.listdir(extract_dir)) > 0 + + +def test_uncompress_upper_archive_extension(tmp_path, datadir): + """Copy test archives in a temporary directory but turn their names + to uppercase, then check they can be successfully extracted. + """ + archives_path = os.path.join(datadir, "archives") + archive_files = [ + f + for f in os.listdir(archives_path) + if os.path.isfile(os.path.join(archives_path, f)) + ] + for archive_file in archive_files: + archive_file_upper = os.path.join(tmp_path, archive_file.upper()) + extract_dir = os.path.join(tmp_path, archive_file) + shutil.copy(os.path.join(archives_path, archive_file), archive_file_upper) + tarball.uncompress(archive_file_upper, extract_dir) + assert len(os.listdir(extract_dir)) > 0