classification
Title: relative symlinks in tarfile.extract broken (windows)
Type: behavior Stage: test needed
Components: Windows Versions: Python 3.3, Python 3.2
process
Status: open Resolution:
Dependencies: tarfile tarinfo.extract*() broken with symlinks
View: 12926
Superseder:
Assigned To: lars.gustaebel Nosy List: Patrick.von.Reth, brian.curtin, lars.gustaebel
Priority: normal Keywords:

Created on 2012-01-03 16:42 by Patrick.von.Reth, last changed 2012-01-05 17:24 by lars.gustaebel.

Messages (4)
msg150512 - (view) Author: Patrick von Reth (Patrick.von.Reth) Date: 2012-01-03 16:42
when extracting http://www.openssl.org/source/openssl-1.0.0d.tar.gz with python3.2 on windows 7 extraction fails with 

  File "C:\python32\lib\tarfile.py", line 2175, in extract
    set_attrs=set_attrs)
  File "C:\python32\lib\tarfile.py", line 2259, in _extract_member
    self.makelink(tarinfo, targetpath)
  File "C:\python32\lib\tarfile.py", line 2359, in makelink
    targetpath)
  File "C:\python32\lib\tarfile.py", line 2251, in _extract_member
    self.makefile(tarinfo, targetpath)
  File "C:\python32\lib\tarfile.py", line 2292, in makefile
    target = bltn_open(targetpath, "wb")
IOError: [Errno 22] Invalid argument: 'R:\\tmp\\os\\openssl-1.0.0d\\apps\\md4.c'

the reason is that the symlink is broken

R:\>dir R:\tmp\os\openssl-1.0.0d\apps\md4.c
 Volume in drive R has no label.
 Volume Serial Number is E8F0-7223
 Directory of R:\tmp\os\openssl-1.0.0d\apps
02.01.2012  20:13    <SYMLINK>      md4.c [../crypto/md4/md4.c]

it must be backslashes instead of front slashes and that's why python cant access the file the symlink is pointing to.
msg150671 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2012-01-05 16:47
You actually hit two bugs at the same time here: The target of the created symlink was not translated from unix to windows path delimiters and is therefore broken. The second bug is issue12926 which leads to the error in TarFile.makefile(). 

Brian, AFAIK all file-specific functions on windows accept forward slashes in pathnames, right? Has this been discussed in the course of the windows implementation of os.symlink()? I could certainly fix the slash translation in tarfile.py, but may be it's os.symlink() that should been fixed.
msg150672 - (view) Author: Patrick von Reth (Patrick.von.Reth) Date: 2012-01-05 17:21
to ignore the bug I also tried dereference=True, but it looks like python3 is ignoring it for extraction.
Is this the normal behavior or just another bug?
msg150673 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2012-01-05 17:24
The dereference option is only used for archive creation, so the contents of the file a symbolic link is pointing to is added instead of the symbolic link itself.
History
Date User Action Args
2012-01-05 17:24:12lars.gustaebelsetmessages: + msg150673
2012-01-05 17:21:00Patrick.von.Rethsetmessages: + msg150672
2012-01-05 16:47:31lars.gustaebelsetdependencies: + tarfile tarinfo.extract*() broken with symlinks
messages: + msg150671
2012-01-04 06:14:34lars.gustaebelsetassignee: lars.gustaebel

nosy: + lars.gustaebel
versions: + Python 3.3
2012-01-04 04:32:57brian.curtinsetnosy: + brian.curtin

stage: test needed
2012-01-03 16:43:28Patrick.von.Rethsettitle: relative symlinks in tarfile.extract broken -> relative symlinks in tarfile.extract broken (windows)
2012-01-03 16:42:43Patrick.von.Rethcreate