Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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)
-----------------------------

Expand Down
8 changes: 6 additions & 2 deletions src/commoncode/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions src/commoncode/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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)
Expand Down
Binary file modified tests/data/filetype/types.tar
Binary file not shown.
5 changes: 4 additions & 1 deletion tests/test_filetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -61,6 +63,7 @@ def test_get_type(self):
if on_posix:
expected += [
("2-SYMTYPE", "l"),
("6-FIFOTYPE", "s"),
]

try:
Expand Down