This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: 2.7 regression in tarfile: IOError: link could not be created
Type: crash Stage: resolved
Components: Library (Lib), Windows Versions: Python 3.2, Python 2.7
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: lars.gustaebel Nosy List: lars.gustaebel, orsenthil, srid
Priority: normal Keywords:

Created on 2010-05-17 17:45 by srid, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (7)
msg105920 - (view) Author: Sridhar Ratnakumar (srid) Date: 2010-05-17 17:45
Repro steps:

Download (via 'eternity' module in PyPI) and look at the following command line session:

C:\Temp\tfbug>python27 -c "import tarfile as T;'eternity-0.13.tar.gz').extractall()"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python27\lib\", line 2046, in extractall
    self.extract(tarinfo, path)
  File "C:\Python27\lib\", line 2083, in extract
    self._extract_member(tarinfo, os.path.join(path,
  File "C:\Python27\lib\", line 2168, in _extract_member
    self.makelink(tarinfo, targetpath)
  File "C:\Python27\lib\", line 2260, in makelink
    raise IOError("link could not be created")
IOError: link could not be created

C:\Temp\tfbug>python26 -c "import tarfile as T;'eternity-0.13.tar.gz').extractall()"

C:\Temp\tfbug>dir eternity-0.13
 Volume in drive C has no label.
 Volume Serial Number is 1877-E6BA

 Directory of C:\Temp\tfbug\eternity-0.13

10/14/2008  06:08 PM    <DIR>          .
10/14/2008  06:08 PM    <DIR>          ..
09/05/2008  01:31 PM               115 AUTHORS
10/14/2008  06:08 PM    <DIR>          bin
09/05/2008  01:31 PM                 0 CHANGES
09/05/2008  01:31 PM            17,998 COPYING
10/14/2008  06:08 PM    <DIR>          etc
09/05/2008  01:31 PM               447 INSTALL
09/11/2008  06:06 PM               231
10/14/2008  06:08 PM               802 PKG-INFO
09/05/2008  01:31 PM               516 README
09/10/2008  04:10 PM             2,948
10/14/2008  06:08 PM    <DIR>          src
               8 File(s)         23,057 bytes
               5 Dir(s)   3,493,781,504 bytes free

msg105925 - (view) Author: Sridhar Ratnakumar (srid) Date: 2010-05-17 18:07
The actual exception caught (before it was ignored and a generic IOError was thrown) was this:

  File "C:\Python27\lib\", line 2168, in _extract_member
    self.makelink(tarinfo, targetpath)
  File "C:\Python27\lib\", line 2258, in makelink
    shutil.copy2(linkpath, targetpath)
  File "C:\Python27\lib\", line 127, in copy2
    copyfile(src, dst)
  File "C:\Python27\lib\", line 81, in copyfile
    with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: 'eternity-0.13\\src\\eternity\\django\\templates\\eui\\concerns\\..\\registry\\delet

The specified file actually does not exist. Perhaps, in the middle of the extraction process, it was not created *yet*.
msg105926 - (view) Author: Sridhar Ratnakumar (srid) Date: 2010-05-17 18:09
Aside: why is the original exception ignored, and instead a generic IOError is thrown? Why not use one of the exceptions inheriting `TarError`, so that application code can reliably catch these errors?
msg105979 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-05-18 14:25
This is a platform specific bug. It is happening only on windows.
BTW, makelink should not have been called for this file, because it
is not a link or symlink, but a regular file.
msg105982 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2010-05-18 14:59
@senthil: Yes, this is a platform-specific problem. The code that is failing is in fact supposed to somehow "emulate" symlink and hardlink extraction on platforms that don't support these, e.g. Windows. What tarfile is trying to do here is to extract links as if they were regular files.

@sridhar: Thanks for the detailed report. I am currently working on the problem.
msg105987 - (view) Author: Sridhar Ratnakumar (srid) Date: 2010-05-18 16:01
Thanks - just a suggestion: it may be a good idea to add a test case for this makelink emulation code.

Also, any thoughts on raising (a derived class of) TarError instead of IOError?
msg106947 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2010-06-03 12:49
I have just committed the fix. I hope that this code is now more robust. See r81667 (trunk) and r81670 (py3k).

Thank you very much for your report!
Date User Action Args
2022-04-11 14:57:01adminsetgithub: 52987
2010-06-03 12:49:57lars.gustaebelsetstatus: open -> closed
versions: + Python 3.2
messages: + msg106947

resolution: accepted
stage: resolved
2010-05-18 16:01:23sridsetmessages: + msg105987
2010-05-18 14:59:35lars.gustaebelsetmessages: + msg105982
2010-05-18 14:25:49orsenthilsetnosy: + orsenthil
messages: + msg105979
2010-05-18 10:41:21lars.gustaebelsetassignee: lars.gustaebel
2010-05-17 18:09:15sridsetmessages: + msg105926
2010-05-17 18:07:09sridsetmessages: + msg105925
2010-05-17 17:45:43sridcreate