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.py: better use of TarInfo objects with longnames
Type: Stage:
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, lars.gustaebel
Priority: normal Keywords: patch

Created on 2006-10-24 16:38 by lars.gustaebel, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tarinfo-attrs.diff lars.gustaebel, 2006-10-24 16:38 patch against Lib/tarfile.py
tarinfo-attrs2.diff lars.gustaebel, 2006-10-25 19:57 patch against Lib/tarfile.py
Messages (3)
msg51281 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2006-10-24 16:38
When a TarInfo object with a long name is added to a
TarFile, the .name attribute is garbled during the
special processing involved with long names. This is
true for both posix and gnu mode and has historical
"design" reasons.

In posix mode, a long name is split in two. TarInfo's
prefix attr gets the first part, the name attr the
second one.
In gnu mode, a long name is truncated up to LENGTH_NAME
(100) chars and stored the TarInfo's name attr.

So, if you open a TarFile for writing, add a few files
with long names to it and call the getnames() method
for that still open file, the names returned are all
cut. The getmember() method will not work, because all
names have changed.

On top of that, if a user adds a TarInfo object to a
TarFile it is not copied. So, it is undefined what
happens if the user uses the same TarInfo object
several times with changed attributes. The problem
described in bug #1583537 (now deleted) was partly
caused by this.

The attached patch makes it possible to use the same
TarInfo object several times by copying it in
TarFile.addfile(), removes the (undocumented)
TarInfo.prefix attr and leaves TarInfo.name alone.

I think this should be backported to 2.5 as well.
msg51282 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2006-10-25 19:57
Logged In: YES 
user_id=642936

I spent some more time on the patch and went a bit further.
I moved the _create_gnulong() method from TarFile to
TarInfo, so TarInfo.tobuf() is now able to create GNU
extensions by itself. The distinction between posix and
non-posix mode is very clear in the code now. The
TarFile.addfile() method is cleaner as well.
The only drawback might be that the _dbg calls ("Created GNU
extension ... ") are gone now.
msg51283 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-10-29 09:16
Logged In: YES 
user_id=849994

Committed as rev. 52524, 52525 (2.5).
History
Date User Action Args
2022-04-11 14:56:20adminsetgithub: 44164
2006-10-24 16:38:21lars.gustaebelcreate