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
11 changes: 5 additions & 6 deletions conan/tools/files/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import platform
import shutil
import subprocess
import sys
from typing import Optional
from contextlib import contextmanager
from fnmatch import fnmatch
Expand Down Expand Up @@ -373,9 +374,10 @@ def unzip(conanfile, filename, destination=".", keep_permissions=False, pattern=
output = conanfile.output
extract_filter = conanfile.conf.get("tools.files.unzip:filter") or extract_filter
output.info(f"Uncompressing {filename} to {destination}")
if (filename.endswith(".tar.gz") or filename.endswith(".tgz") or
filename.endswith(".tbz2") or filename.endswith(".tar.bz2") or
filename.endswith(".tar")):
if (filename.endswith((".tar.gz", ".tgz", ".tbz2", ".tar.bz2", ".tar", ".tar.xz", ".txz", ".tar.zst", ".tzst"))):
if filename.endswith((".tar.zst", ".tzst")) and sys.version_info.minor < 14:
raise ConanException(f"File {os.path.basename(filename)} compressed with 'zst', "

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, just be aware of using this for ConanCenter recipes, as it will trigger this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is right, we may need to upgrade to 3.14 eventually!

f"unsupported for Python<3.14 ")
return untargz(filename, destination, pattern, strip_root, extract_filter,
excludes=excludes)
if filename.endswith(".gz"):
Expand All @@ -387,9 +389,6 @@ def unzip(conanfile, filename, destination=".", keep_permissions=False, pattern=
with open(target_name, "wb") as fout:
shutil.copyfileobj(fin, fout)
return
if filename.endswith(".tar.xz") or filename.endswith(".txz"):
return untargz(filename, destination, pattern, strip_root, extract_filter,
excludes=excludes)

import zipfile
full_path = os.path.normpath(os.path.join(os.getcwd(), destination))
Expand Down
31 changes: 31 additions & 0 deletions test/unittests/tools/files/test_zipping.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
import sys
import zipfile
import tarfile
from os.path import join, exists
Expand Down Expand Up @@ -171,3 +173,32 @@ def test_untargz_with_strip_root_and_pattern():
unzip(conanfile, archive, dest_dir, pattern="src/*", strip_root=True)
assert exists(join(dest_dir, "bar.txt"))
assert not exists(join(dest_dir, "foo.txt"))


@pytest.mark.skipif(sys.version_info.minor < 14, reason="zstd needs Python >= 3.14")
def test_untargz_zst():
tmp_dir = temp_folder()
tar_path = join(tmp_dir, "file.tar.zst")
foo_txt = join(tmp_dir, "foo.txt")
save(foo_txt, "foo-content")
with tarfile.open(tar_path, "w:zst") as tar:
tar.add(foo_txt, "foo.txt")

conanfile = ConanFileMock({})
dest_dir = temp_folder()
unzip(conanfile, tar_path, dest_dir)
assert exists(join(dest_dir, "foo.txt"))


@pytest.mark.skipif(sys.version_info.minor >= 14, reason="validate zstd error in python<3.14")
def test_untargz_zst_unsupported_python():
# Fake a .tar.zst, the version check happens before any decompression is attempted
archive = create_example_tar()
zst_archive = join(os.path.dirname(archive), "file.tzst")
os.rename(archive, zst_archive)

conanfile = ConanFileMock({})
dest_dir = temp_folder()
with pytest.raises(ConanException) as error:
unzip(conanfile, zst_archive, dest_dir)
assert "File file.tzst compressed with 'zst', unsupported for Python<3.14" in str(error.value)
Loading