diff options
author | Brian Curtin <brian.curtin@gmail.com> | 2010-07-09 13:54:27 (GMT) |
---|---|---|
committer | Brian Curtin <brian.curtin@gmail.com> | 2010-07-09 13:54:27 (GMT) |
commit | 16633fa497caec98c5aa86afb99fb4e9c27f3b62 (patch) | |
tree | b99e6086d236921cbc1928cd9f0f03312e4f435c /Lib/tarfile.py | |
parent | 4b83af957629197050f61988183f56564892ab94 (diff) | |
download | cpython-16633fa497caec98c5aa86afb99fb4e9c27f3b62.zip cpython-16633fa497caec98c5aa86afb99fb4e9c27f3b62.tar.gz cpython-16633fa497caec98c5aa86afb99fb4e9c27f3b62.tar.bz2 |
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.
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r-- | Lib/tarfile.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py index aca934a..bf6129e 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -55,6 +55,15 @@ try: except ImportError: 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 * __all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"] @@ -2283,17 +2292,16 @@ class TarFile(object): os.link(tarinfo._link_target, targetpath) else: self._extract_mem - except (AttributeError, NotImplementedError, WindowsError): - # AttributeError if no os.symlink - # NotImplementedError if on Windows XP - # WindowsError (1314) if the required privilege is not held by the client + except symlink_exception: 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: linkpath = tarinfo.linkname else: try: - self._extract_member(self._find_link_target(tarinfo), targetpath) + self._extract_member(self._find_link_target(tarinfo), + targetpath) except KeyError: raise ExtractError("unable to resolve link inside archive") |