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.

classification
Title: TarFile doesn't support member files with a leading "./"
Type: behavior Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: lars.gustaebel Nosy List: free.ekanayaka, lars.gustaebel, niemeyer
Priority: normal Keywords:

Created on 2010-06-24 18:11 by free.ekanayaka, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg108537 - (view) Author: Free Ekanayaka (free.ekanayaka) Date: 2010-06-24 18:10
The tar format allows to have memeber files whose path has a leading "./":

$ echo > foo
$ tar cf bar.tar ./foo
$ tar tf bar.tar 
./foo

However the tarfile module doesn't allow this:

>>> from StringIO import StringIO
>>> from tarfile import TarInfo, TarFile
>>> info = TarInfo("./foo")
>>> fd = open("bar.tar", "w")
>>> tar = TarFile.open(fileobj=fd, mode="w")
>>> tar.addfile(info, "")
>>> tar.close()

then:

$ tar tf bar.tar 
foo

So in practice the tarfile module forces the removal of leading "./"'s.

In particular this is a problem when creating .deb files (dpkg) programmatically as these contains tar files with members with a leading "./".
msg108540 - (view) Author: Gustavo Niemeyer (niemeyer) * (Python committer) Date: 2010-06-24 18:23
Please note that even if unpacking such a tar might be semantically equivalent to a version which strips out the "./" prefix, it should be possible to create a tar with valid path names such as these.

In the case of debs, for instance, the files inside the tarball may contain expected path names, which means that some (badly done, perhaps) tools could *expect* the file to be exactly that which is created by the standard tools (e.g. "./debian/control"), and break down once it's not found.

With this in mind, it would indeed be nice to be able to use paths prefixed with "./" in Python's tarfile.
msg108580 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2010-06-25 07:20
This is a duplicate of issue6054 which has been fixed in Python 2.7 (r74571).

(Hi, Gustavo!)
msg108582 - (view) Author: Free Ekanayaka (free.ekanayaka) Date: 2010-06-25 10:01
Thanks for the prompt reply! Cool to know this is already fixed.
msg108927 - (view) Author: Gustavo Niemeyer (niemeyer) * (Python committer) Date: 2010-06-29 18:30
Indeed, nice use of the time machine! :-)

Thanks Lars!
History
Date User Action Args
2022-04-11 14:57:02adminsetgithub: 53317
2010-06-29 18:30:35niemeyersetmessages: + msg108927
2010-06-25 10:01:02free.ekanayakasetmessages: + msg108582
2010-06-25 07:20:16lars.gustaebelsetstatus: open -> closed

nosy: + lars.gustaebel
messages: + msg108580

assignee: lars.gustaebel
resolution: duplicate
2010-06-24 18:23:29niemeyersetnosy: + niemeyer
messages: + msg108540
2010-06-24 18:11:00free.ekanayakacreate