summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-11-06 15:38:14 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-11-06 15:38:14 +0900
commit66eeac0d81ec3d109ff6175e8190e08c4659b561 (patch)
tree880d54f79eab9625fb8eb59f2656c2183d6b1cbe
parent507ad47481ce7369a202077ab291eb0ba743c517 (diff)
downloadbuildstream-66eeac0d81ec3d109ff6175e8190e08c4659b561.tar.gz
plugins/sources/zip.py: Dont depend on python 3.6 method
Also, restructured a bit to match tar source, there was never any need for the `dirs_only` parameter for listing the archive paths, the source is only interested in directories anyway.
-rw-r--r--buildstream/plugins/sources/zip.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/buildstream/plugins/sources/zip.py b/buildstream/plugins/sources/zip.py
index e2c5ee38c..495aa6d00 100644
--- a/buildstream/plugins/sources/zip.py
+++ b/buildstream/plugins/sources/zip.py
@@ -100,11 +100,15 @@ class ZipSource(DownloadableFileSource):
# We want to iterate over all paths of an archive, but namelist()
# is not enough because some archives simply do not contain the leading
# directory paths for the archived files.
- def _list_archive_paths(self, archive, dirs_only=False):
+ def _list_archive_paths(self, archive):
visited = {}
for member in archive.infolist():
- if not member.is_dir():
+
+ # ZipInfo.is_dir() is only available in python >= 3.6, but all
+ # it does is check for a trailing '/' in the name
+ #
+ if not member.filename.endswith('/'):
# Loop over the components of a path, for a path of a/b/c/d
# we will first visit 'a', then 'a/b' and then 'a/b/c', excluding
@@ -119,23 +123,21 @@ class ZipSource(DownloadableFileSource):
# exist in the archive
_ = archive.getinfo(dir_component)
except KeyError:
- yield dir_component
+ if dir_component != '.':
+ yield dir_component
continue
# Avoid considering the '.' directory, if any is included in the archive
# this is to avoid the default 'base-dir: *' value behaving differently
# depending on whether the archive was encoded with a leading '.' or not
- elif member.filename == './':
- continue
-
- if dirs_only and not member.is_dir():
+ elif member.filename == '.' or member.filename == './':
continue
yield member.filename
def _find_base_dir(self, archive, pattern):
- paths = self._list_archive_paths(archive, dirs_only=True)
+ paths = self._list_archive_paths(archive)
matches = sorted(list(utils.glob(paths, pattern)))
if not matches:
raise SourceError("{}: Could not find base directory matching pattern: {}".format(self, pattern))