diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 25495220..dc638663 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,12 @@ Release notes ============= +Version 32.4.2 - (2025-01-08) +----------------------------- + +- Support setting the tar archive filter in python3.14 + https://github.com/aboutcode-org/commoncode/issues/88 + Version 32.4.1 - (2025-01-07) ----------------------------- diff --git a/src/commoncode/archive.py b/src/commoncode/archive.py index 3c0c7583..1d3e42cc 100644 --- a/src/commoncode/archive.py +++ b/src/commoncode/archive.py @@ -14,6 +14,7 @@ from os import path from commoncode.system import on_windows +from commoncode.system import py314 """ Mimimal tar and zip file handling, primarily for testing. @@ -39,7 +40,7 @@ def _extract_tar_raw(test_path, target_dir, to_bytes, *args, **kwargs): extract_tar_uni = partial(_extract_tar_raw, to_bytes=False) -def extract_tar(location, target_dir, verbatim=False, *args, **kwargs): +def extract_tar(location, target_dir, verbatim=False, filter=None, *args, **kwargs): """ Extract a tar archive at location in the target_dir directory. If `verbatim` is True preserve the permissions. @@ -58,7 +59,10 @@ def extract_tar(location, target_dir, verbatim=False, *args, **kwargs): if not verbatim: tarinfo.mode = 0o755 to_extract.append(tarinfo) - tar.extractall(target_dir, members=to_extract) + if py314 and filter: + tar.extractall(target_dir, members=to_extract, filter=filter) + else: + tar.extractall(target_dir, members=to_extract) finally: if tar: tar.close() diff --git a/src/commoncode/testcase.py b/src/commoncode/testcase.py index 525bf666..2a7b37a9 100644 --- a/src/commoncode/testcase.py +++ b/src/commoncode/testcase.py @@ -194,7 +194,7 @@ def remove_vcs(self, test_dir): for tf in tilde_files: os.remove(tf) - def __extract(self, test_path, extract_func=None, verbatim=False): + def __extract(self, test_path, extract_func=None, verbatim=False, filter=None): """ Given an archive file identified by test_path relative to a test files directory, return a new temp directory where the @@ -206,7 +206,7 @@ def __extract(self, test_path, extract_func=None, verbatim=False): target_path = path.basename(test_path) target_dir = self.get_temp_dir(target_path) original_archive = self.get_test_loc(test_path) - extract_func(original_archive, target_dir, verbatim=verbatim) + extract_func(original_archive, target_dir, verbatim=verbatim, filter=filter) return target_dir def extract_test_zip(self, test_path, *args, **kwargs): @@ -215,8 +215,8 @@ def extract_test_zip(self, test_path, *args, **kwargs): def extract_test_zip_raw(self, test_path, *args, **kwargs): return self.__extract(test_path, extract_zip_raw) - def extract_test_tar(self, test_path, verbatim=False): - return self.__extract(test_path, extract_tar, verbatim) + def extract_test_tar(self, test_path, verbatim=False, filter=None): + return self.__extract(test_path, extract_tar, verbatim, filter) def extract_test_tar_raw(self, test_path, *args, **kwargs): return self.__extract(test_path, extract_tar_raw) diff --git a/tests/data/filetype/types.tar b/tests/data/filetype/types.tar index 24fc04c4..458dc447 100644 Binary files a/tests/data/filetype/types.tar and b/tests/data/filetype/types.tar differ diff --git a/tests/test_filetype.py b/tests/test_filetype.py index c5703872..9265314c 100644 --- a/tests/test_filetype.py +++ b/tests/test_filetype.py @@ -34,7 +34,9 @@ def test_get_size_on_directory(self): assert filetype.get_size(test_dir) == 12400 def test_get_type(self): - test_dir = self.extract_test_tar("filetype/types.tar", verbatim=True) + test_dir = self.extract_test_tar( + "filetype/types.tar", verbatim=True, filter="fully_trusted" + ) results = [] for root, dirs, files in os.walk(test_dir): for d in dirs: @@ -61,6 +63,7 @@ def test_get_type(self): if on_posix: expected += [ ("2-SYMTYPE", "l"), + ("6-FIFOTYPE", "s"), ] try: