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
12 changes: 12 additions & 0 deletions Lib/test/test_zipfile/_path/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,18 @@ def test_is_symlink(self, alpharep):
assert not root.joinpath('a.txt').is_symlink()
assert root.joinpath('n.txt').is_symlink()

@pass_alpharep
def test_is_symlink_missing(self, alpharep):
"""
is_symlink returns False for entries missing from the archive
(including the root and implied directories) rather than
raising KeyError.
"""
root = zipfile.Path(alpharep)
assert not root.is_symlink()
assert not root.joinpath('b').is_symlink()
assert not root.joinpath('missing.txt').is_symlink()

@pass_alpharep
def test_relative_to(self, alpharep):
root = zipfile.Path(alpharep)
Expand Down
5 changes: 4 additions & 1 deletion Lib/zipfile/_path/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,10 @@ def is_symlink(self):
"""
Return whether this path is a symlink.
"""
info = self.root.getinfo(self.at)
try:
info = self.root.getinfo(self.at)
except KeyError:
return False
mode = info.external_attr >> 16
return stat.S_ISLNK(mode)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix :meth:`zipfile.Path.is_symlink` raising :exc:`KeyError` for paths not
present in the archive. It now returns ``False``, consistent with the other
:class:`zipfile.Path` predicates and with :meth:`pathlib.Path.is_symlink`.
Loading