[issue6856] allow setting uid and gid when creating tar files

Lars Gustäbel report at bugs.python.org
Mon Sep 7 13:52:25 CEST 2009


Lars Gustäbel <lars at gustaebel.de> added the comment:

TarInfo does not need set_uid() or set_gid() methods, both can be set
using the uid and gid attributes.
If the list of files to add to the archive is known you can do this:

tar = tarfile.open("foo.tar.gz", "w:gz")
for filename in filenames:
  tarinfo = tar.gettarinfo(filename)
  if tarinfo.isreg():
    fobj = open(filename)
  else:
    fobj = None
  tarinfo.uid = 0
  tarinfo.gid = 0
  tar.addfile(tarinfo, fobj)
tar.close()

I am not against adding a new option. Although, it's too bad that I
added the exclude option in 2.6 not long ago, which does something very
similar and would again be replaced by this more general "include"
option. BTW, I think calling the option "filter" would be more suitable
for what it's doing.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6856>
_______________________________________


More information about the Python-bugs-list mailing list