Skip to content

Commit

Permalink
chore: use filter arg for tar.extractall (#5856)
Browse files Browse the repository at this point in the history
Deprecation warning:
DeprecationWarning: Python 3.14 will, by default, filter extracted tar
archives and reject files or modify their metadata. Use the filter
argument to control this behavior.

Refs:

https://docs.python.org/3/library/tarfile.html#tarfile-extraction-filter
https://peps.python.org/pep-0706/

GH-5175
  • Loading branch information
aciba90 committed Nov 13, 2024
1 parent cd74e99 commit 5950099
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/unittests/cmd/devel/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import glob
import os
import pathlib
import sys
import tarfile
from datetime import datetime, timezone

Expand Down Expand Up @@ -140,8 +141,12 @@ def test_collect_logs_end_to_end(self, mocker, tmp_path):
)
extract_to = tmp_path / "extracted"
extract_to.mkdir()

tar_kwargs = {}
if sys.version_info > (3, 11):
tar_kwargs = {"filter": "fully_trusted"}
with tarfile.open(tmp_path / "cloud-init.tar.gz") as tar:
tar.extractall(extract_to)
tar.extractall(extract_to, **tar_kwargs) # type: ignore[arg-type]
extracted_dir = extract_to / f"cloud-init-logs-{today}"

for name in to_collect:
Expand Down

0 comments on commit 5950099

Please sign in to comment.