Skip to content

Commit

Permalink
Merge pull request #90 from jaraco/bugfix/gh-101566-extractall
Browse files Browse the repository at this point in the history
Bugfix for KeyError when implied dirs are present.
  • Loading branch information
jaraco authored Feb 5, 2023
2 parents 0a47dda + 7bf2869 commit e38bfbb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v3.12.1
=======

* gh-101566: In ``CompleteDirs``, override ``ZipFile.getinfo``
to supply a ``ZipInfo`` for implied dirs.

v3.12.0
=======

Expand Down
11 changes: 11 additions & 0 deletions tests/test_zipp.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,14 @@ def test_pickle(self, alpharep, path_type, subpath):
restored_1 = pickle.loads(saved_1)
first, *rest = restored_1.iterdir()
assert first.read_text().startswith('content of ')

@pass_alpharep
def test_extract_orig_with_implied_dirs(self, alpharep):
"""
A zip file wrapped in a Path should extract even with implied dirs.
"""
source_path = self.zipfile_ondisk(alpharep)
zf = zipfile.ZipFile(source_path)
# wrap the zipfile for its side effect
zipp.Path(zf)
zf.extractall(source_path.parent)
11 changes: 11 additions & 0 deletions zipp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ def resolve_dir(self, name):
dir_match = name not in names and dirname in names
return dirname if dir_match else name

def getinfo(self, name):
"""
Supplement getinfo for implied dirs.
"""
try:
return super(CompleteDirs, self).getinfo(name)
except KeyError:
if not name.endswith('/') or name not in self._name_set():
raise
return zipfile.ZipInfo(filename=name)

@classmethod
def make(cls, source):
"""
Expand Down

0 comments on commit e38bfbb

Please sign in to comment.