Skip to content
Open
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
10 changes: 10 additions & 0 deletions conan/api/subapi/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,16 @@ def restore(self, path) -> PackagesList:
fileobj = the_tar.extractfile("pkglist.json")
pkglist = fileobj.read()
the_tar.extraction_filter = (lambda member, _: member) # fully_trusted (Py 3.14)

import stat
for member in the_tar.getmembers():
target_path = os.path.join(cache_folder, member.name)
if os.path.exists(target_path):
try:
os.chmod(target_path, stat.S_IWRITE | stat.S_IREAD)
except Exception:
pass

the_tar.extractall(path=cache_folder)
the_tar.close()

Expand Down
1 change: 1 addition & 0 deletions conan/tools/gnu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from conan.tools.gnu.pkgconfig import PkgConfig
from conan.tools.gnu.pkgconfigdeps import PkgConfigDeps
from conan.tools.gnu.makedeps import MakeDeps
from conan.tools.gnu.helpers import is_mingw
16 changes: 16 additions & 0 deletions conan/tools/gnu/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def is_mingw(conanfile, build_context=False):
"""
Validates if the current compiler is MinGW (gcc or clang on Windows).

:param conanfile: ``< ConanFile object >`` The current recipe object. Always use ``self``.
:param build_context: If True, will use the settings from the build context, not host ones
:return: ``bool`` True, if the host compiler is MinGW, otherwise, False.
"""
if not build_context:
settings = conanfile.settings
else:
settings = conanfile.settings_build

os_ = settings.get_safe("os")
compiler = settings.get_safe("compiler")
return os_ == "Windows" and compiler in ("gcc", "clang")
22 changes: 22 additions & 0 deletions test/unittests/tools/gnu/test_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
from conan.tools.gnu.helpers import is_mingw
from conan.test.utils.mocks import ConanFileMock, MockSettings

def test_is_mingw():
# Test True
settings = MockSettings({"os": "Windows", "compiler": "gcc"})
conanfile = ConanFileMock()
conanfile.settings = settings
assert is_mingw(conanfile) is True

settings.values["compiler"] = "clang"
assert is_mingw(conanfile) is True

# Test False
settings.values["compiler"] = "msvc"
assert is_mingw(conanfile) is False

settings.values["os"] = "Linux"
settings.values["compiler"] = "gcc"
assert is_mingw(conanfile) is False