mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Fix the breakage of Lib/tarfile.py on non-Windows platforms due to
using WindowsError in a try/except. Only add WindowsError to the list of exceptions to catch when we are actually running on Windows. Additionally, add a call that was left out in test_posixpath. Thanks Amaury, Antoine, and Jason.
This commit is contained in:
parent
4b83af9576
commit
16633fa497
2 changed files with 15 additions and 6 deletions
|
@ -55,6 +55,15 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
grp = pwd = None
|
grp = pwd = None
|
||||||
|
|
||||||
|
# os.symlink on Windows prior to 6.0 raises NotImplementedError
|
||||||
|
symlink_exception = (AttributeError, NotImplementedError)
|
||||||
|
try:
|
||||||
|
# WindowsError (1314) will be raised if the caller does not hold the
|
||||||
|
# SeCreateSymbolicLinkPrivilege privilege
|
||||||
|
symlink_exception += (WindowsError,)
|
||||||
|
except NameError:
|
||||||
|
pass
|
||||||
|
|
||||||
# from tarfile import *
|
# from tarfile import *
|
||||||
__all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"]
|
__all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"]
|
||||||
|
|
||||||
|
@ -2283,17 +2292,16 @@ class TarFile(object):
|
||||||
os.link(tarinfo._link_target, targetpath)
|
os.link(tarinfo._link_target, targetpath)
|
||||||
else:
|
else:
|
||||||
self._extract_mem
|
self._extract_mem
|
||||||
except (AttributeError, NotImplementedError, WindowsError):
|
except symlink_exception:
|
||||||
# AttributeError if no os.symlink
|
|
||||||
# NotImplementedError if on Windows XP
|
|
||||||
# WindowsError (1314) if the required privilege is not held by the client
|
|
||||||
if tarinfo.issym():
|
if tarinfo.issym():
|
||||||
linkpath = os.path.join(os.path.dirname(tarinfo.name),tarinfo.linkname)
|
linkpath = os.path.join(os.path.dirname(tarinfo.name),
|
||||||
|
tarinfo.linkname)
|
||||||
else:
|
else:
|
||||||
linkpath = tarinfo.linkname
|
linkpath = tarinfo.linkname
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self._extract_member(self._find_link_target(tarinfo), targetpath)
|
self._extract_member(self._find_link_target(tarinfo),
|
||||||
|
targetpath)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise ExtractError("unable to resolve link inside archive")
|
raise ExtractError("unable to resolve link inside archive")
|
||||||
|
|
||||||
|
|
|
@ -208,6 +208,7 @@ class PosixPathTest(unittest.TestCase):
|
||||||
def test_samestat_on_links(self):
|
def test_samestat_on_links(self):
|
||||||
test_fn1 = support.TESTFN + "1"
|
test_fn1 = support.TESTFN + "1"
|
||||||
test_fn2 = support.TESTFN + "2"
|
test_fn2 = support.TESTFN + "2"
|
||||||
|
self._create_file(test_fn1)
|
||||||
test_fns = (test_fn1, test_fn2)
|
test_fns = (test_fn1, test_fn2)
|
||||||
os.symlink(*test_fns)
|
os.symlink(*test_fns)
|
||||||
stats = map(os.stat, test_fns)
|
stats = map(os.stat, test_fns)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue