diff --git a/fusesoc/provider/github.py b/fusesoc/provider/github.py index 22cd41cc..fc08fa24 100644 --- a/fusesoc/provider/github.py +++ b/fusesoc/provider/github.py @@ -9,6 +9,8 @@ from fusesoc.provider.provider import Provider +_HAS_TAR_FILTER = hasattr(tarfile, "tar_filter") # Requires Python 3.12 + logger = logging.getLogger(__name__) if sys.version_info[0] >= 3: @@ -41,5 +43,10 @@ def _checkout(self, local_dir): # Ugly hack to get the first part of the directory name of the extracted files tmp = t.getnames()[0] - t.extractall(cache_root) + + extraction_arguments = {"path": cache_root} + if _HAS_TAR_FILTER: + extraction_arguments["filter"] = "data" + t.extractall(**extraction_arguments) + os.rename(os.path.join(cache_root, tmp), os.path.join(cache_root, core)) diff --git a/fusesoc/provider/url.py b/fusesoc/provider/url.py index 023fe126..8a7b13fc 100644 --- a/fusesoc/provider/url.py +++ b/fusesoc/provider/url.py @@ -21,6 +21,8 @@ from fusesoc.provider.provider import Provider +_HAS_TAR_FILTER = hasattr(tarfile, "tar_filter") # Requires Python 3.12 + class Url(Provider): def _checkout(self, local_dir): @@ -44,7 +46,10 @@ def _checkout(self, local_dir): filetype = self.config.get("filetype") if filetype == "tar": t = tarfile.open(filename) - t.extractall(local_dir) + extraction_arguments = {"path": local_dir} + if _HAS_TAR_FILTER: + extraction_arguments["filter"] = "data" + t.extractall(**extraction_arguments) elif filetype == "zip": with zipfile.ZipFile(filename, "r") as z: z.extractall(local_dir)