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.gettarinfo modifies self.inodes
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.3
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: lars.gustaebel Nosy List: lars.gustaebel, mgold, mgold-qnx
Priority: low Keywords:

Created on 2011-04-21 15:16 by mgold-qnx, last changed 2022-04-11 14:57 by admin.

Messages (4)
msg134220 - (view) Author: Michael Gold (mgold-qnx) Date: 2011-04-21 15:16
When I call tar.gettarinfo (where tar is a TarFile instance), the inode information is inserted into tar.inodes.  If I later call tar.gettarinfo on a linked file, the returned TarInfo will have type LNKTYPE.

I think it's incorrect to store this information in gettarinfo.  It should be done in addfile.

A comment in gettarinfo states "Is it a hardlink to an already archived file?".  But tar.inodes is modified in gettarinfo, and there's no reason to expect that the file will actually be archived, or will be archived with the same properties.  Bad links could result if the returned tarinfo object were modified before calling addfile.

I suggest changing the code as follows:
 - Create a static method (or non-member function) to fill in a given TarInfo object with stat/lstat/fstat results.  This would need a boolean "dereference" parameter.  (No TarFile instance should be required to create a TarInfo.)
 - Have tar.gettarinfo call the above function; then fill in tarinfo.tarfile, and modify tarinfo.type to LNKNAME if applicable.  Don't modify self.inodes.
 - In tar.addfile, call fstat, and store the inode info into self.inodes.
msg134224 - (view) Author: Michael Gold (mgold-qnx) Date: 2011-04-21 15:45
Actually, TarFile should also have a separate method to take a TarInfo instance and modify its type to LNKTYPE if applicable.  gettarinfo can call that.

This way the user can use a TarInfo object created before any files are added, and can easily get this linking behaviour if desired.

(Note: In my initial message, I had LNKNAME where I meant LNKTYPE.)
msg134264 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2011-04-22 08:12
Good point. Do you happen to have a working implementation already?
msg134299 - (view) Author: Michael Gold (mgold) Date: 2011-04-23 13:23
No, I don't have a working implementation.  (I basically reimplemented TarFile.inodes to work around this; I was using TarFile.dereference, so I already had to do the hard-linking manually.)
History
Date User Action Args
2022-04-11 14:57:16adminsetgithub: 56108
2011-04-23 13:23:27mgoldsetnosy: + mgold
messages: + msg134299
2011-04-22 08:12:17lars.gustaebelsetpriority: normal -> low
assignee: lars.gustaebel
messages: + msg134264

versions: + Python 3.3, - Python 3.2
2011-04-21 15:45:08mgold-qnxsetmessages: + msg134224
2011-04-21 15:16:37mgold-qnxcreate