Skip to content

Commit

Permalink
use extractall(filter=) Python 3.12+ feature (#96)
Browse files Browse the repository at this point in the history
* pass tar_filter to suppress Python warning

* edit changelog
  • Loading branch information
dholth authored Oct 7, 2024
1 parent ac61441 commit d54c487
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[//]: # (current developments)

* Add Python 3.12 to test matrix.
* Pass Python `tarfile.extractall(filter="fully_trusted")` in addition to
internal filtering, when available, to avoid Python 3.12+ `DeprecationWarning`
(#87)
* Improve umask handling. (#106)
* Add `transmute_stream(...)` to create `.conda` from `(TarFile, TarInfo)`. (#90)
iterators, allowing more creative data sources than just `.tar.bz2` inputs.
Expand Down
9 changes: 8 additions & 1 deletion conda_package_streaming/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from . import exceptions, package_streaming

__all__ = ["extract_stream", "extract"]
HAS_TAR_FILTER = hasattr(tarfile, "tar_filter")


def extract_stream(
Expand Down Expand Up @@ -44,7 +45,13 @@ def checked_members():
yield member

try:
tar_file.extractall(path=dest_dir, members=checked_members())
# Drop checked_members() when HAS_TAR_FILTER once we are 100%
# certain the stdlib filter maintains same permissions as
# checked_members().
tar_args = {"path": dest_dir, "members": checked_members()}
if HAS_TAR_FILTER:
tar_args["filter"] = "fully_trusted"
tar_file.extractall(**tar_args)
except OSError as e:
if e.errno == ELOOP:
raise exceptions.CaseInsensitiveFileSystemError() from e
Expand Down
1 change: 0 additions & 1 deletion tests/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ def test_umask(tmp_path, mocker):
mode,
mode & stat_check,
)
assert not mode & stat.S_IWGRP, "%o" % mode


def test_encoding():
Expand Down

0 comments on commit d54c487

Please sign in to comment.