From 4da282a83e28be4f758fa91892119ea0d8382c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kl=C3=B6tzke?= Date: Wed, 21 Jun 2023 21:19:01 +0200 Subject: [PATCH 1/2] url: use python extractor fallbacks only on win32 The tarfile and zipfile Python modules are slower and have behavioural differences compared to their native implementations. The tarfile module in particular differs in the handling of file modes (does not behave like "--no-same-permissions"). The zipfile module looks safer but is certainly slower than the native implementation. As permissions are not an issue on Windows, keep the Python fallbacks at least on native Windows. --- pym/bob/scm/url.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pym/bob/scm/url.py b/pym/bob/scm/url.py index a3c620cf6..c23276205 100644 --- a/pym/bob/scm/url.py +++ b/pym/bob/scm/url.py @@ -117,6 +117,8 @@ def parseUrl(url): return urllib.parse.ParseResult(url.scheme, url.netloc,path, '', '', '') +isWin32 = sys.platform == "win32" + class UrlScm(Scm): DEFAULTS = { @@ -152,23 +154,26 @@ class UrlScm(Scm): (".zip", "zip"), ] + # Use the Python tar/zip extraction only on Windows. They are slower and in + # case of tarfile broken in certain ways (e.g. tarfile will result in + # different file modes!). But it shouldn't make a difference on Windows. EXTRACTORS = { "tar" : [ - ("tar", ["-x", "--no-same-owner", "--no-same-permissions", "-f", "{}"], "--strip-components={}"), - ("python", ["-m", "tarfile", "-e", "{}"], None), + (True, "tar", ["-x", "--no-same-owner", "--no-same-permissions", "-f", "{}"], "--strip-components={}"), + (isWin32, "python", ["-m", "tarfile", "-e", "{}"], None), ], "gzip" : [ - ("gunzip", ["-kf", "{}"], None), + (True, "gunzip", ["-kf", "{}"], None), ], "xz" : [ - ("unxz", ["-kf", "{}"], None), + (True, "unxz", ["-kf", "{}"], None), ], "7z" : [ - ("7z", ["x", "-y", "{}"], None), + (True, "7z", ["x", "-y", "{}"], None), ], "zip" : [ - ("unzip", ["-o", "{}"], None), - ("python", ["-m", "zipfile", "-e", "{}", "."], None), + (True, "unzip", ["-o", "{}"], None), + (isWin32, "python", ["-m", "zipfile", "-e", "{}", "."], None), ], } @@ -416,13 +421,14 @@ def __getExtractors(self): ret = [] for extractor in extractors: + if not extractor[0]: continue if self.__strip > 0: - if extractor[2] is None: + if extractor[3] is None: continue - strip = [extractor[2].format(self.__strip)] + strip = [extractor[3].format(self.__strip)] else: strip = [] - ret.append([extractor[0]] + [a.format(self.__fn) for a in extractor[1]] + strip) + ret.append([extractor[1]] + [a.format(self.__fn) for a in extractor[2]] + strip) if not ret: raise ParseError("Extractor does not support 'stripComponents'!") From 48651e9f1129192f512577df71cd09ca90314af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kl=C3=B6tzke?= Date: Wed, 21 Jun 2023 21:26:02 +0200 Subject: [PATCH 2/2] url: prefer Python extractors on win32 On native Windows it is not always the case that the tar and/or unzip commands are available. Make everybody's life easier by using the Python libraries. There were also cases where non-working binaries were installed in the system. Fixes #496. --- pym/bob/scm/url.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pym/bob/scm/url.py b/pym/bob/scm/url.py index c23276205..b8b09676a 100644 --- a/pym/bob/scm/url.py +++ b/pym/bob/scm/url.py @@ -159,8 +159,8 @@ class UrlScm(Scm): # different file modes!). But it shouldn't make a difference on Windows. EXTRACTORS = { "tar" : [ - (True, "tar", ["-x", "--no-same-owner", "--no-same-permissions", "-f", "{}"], "--strip-components={}"), (isWin32, "python", ["-m", "tarfile", "-e", "{}"], None), + (True, "tar", ["-x", "--no-same-owner", "--no-same-permissions", "-f", "{}"], "--strip-components={}"), ], "gzip" : [ (True, "gunzip", ["-kf", "{}"], None), @@ -172,8 +172,8 @@ class UrlScm(Scm): (True, "7z", ["x", "-y", "{}"], None), ], "zip" : [ - (True, "unzip", ["-o", "{}"], None), (isWin32, "python", ["-m", "zipfile", "-e", "{}", "."], None), + (True, "unzip", ["-o", "{}"], None), ], }