summaryrefslogtreecommitdiffstats
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorBrian Curtin <brian.curtin@gmail.com>2010-07-08 21:39:08 (GMT)
committerBrian Curtin <brian.curtin@gmail.com>2010-07-08 21:39:08 (GMT)
commitd40e6f70a5edabffcbfff22912163520da3a29e2 (patch)
treeef8d44ca974bf606f3437d2ce9977207b8748174 /Lib/tarfile.py
parent0dd8f7890a3396eaef8c740588c65af9422a65a5 (diff)
downloadcpython-d40e6f70a5edabffcbfff22912163520da3a29e2.zip
cpython-d40e6f70a5edabffcbfff22912163520da3a29e2.tar.gz
cpython-d40e6f70a5edabffcbfff22912163520da3a29e2.tar.bz2
Implement #1578269. Patch by Jason R. Coombs.
Added Windows support for os.symlink when run on Windows 6.0 or greater, aka Vista. Previous Windows versions will raise NotImplementedError when trying to symlink. Includes numerous test updates and additions to test_os, including a symlink_support module because of the fact that privilege escalation is required in order to run the tests to ensure that the user is able to create symlinks. By default, accounts do not have the required privilege, so the escalation code will have to be exposed later (or documented on how to do so). I'll be following up with that work next. Note that the tests use ctypes, which was agreed on during the PyCon language summit.
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r--Lib/tarfile.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 4839eb1..aca934a 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -2273,7 +2273,7 @@ class TarFile(object):
(platform limitation), we try to make a copy of the referenced file
instead of a link.
"""
- if hasattr(os, "symlink") and hasattr(os, "link"):
+ try:
# For systems that support symbolic and hard links.
if tarinfo.issym():
os.symlink(tarinfo.linkname, targetpath)
@@ -2282,7 +2282,15 @@ class TarFile(object):
if os.path.exists(tarinfo._link_target):
os.link(tarinfo._link_target, targetpath)
else:
- self._extract_member(self._find_link_target(tarinfo), targetpath)
+ 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
+ if tarinfo.issym():
+ 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)