You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee='https://github.com/gustaebel'closed_at=<Date2009-09-12.10:52:29.458>created_at=<Date2009-09-07.07:47:29.529>labels= ['type-feature', 'library']
title='allow setting uid and gid when creating tar files'updated_at=<Date2009-09-12.10:52:29.456>user='https://github.com/tarekziade'
I am proposing this feature for an issue we have in Distutils: being
able to set the uid/gid of files added in a tar archive using tarfile.
Here's what I am proposing:
adding two methods to TarInfo: set_uid and set_gid, that are able to
take a user and group name *or* a uid and gid number
adding in TarFile a new filter option to add() called include. If
given, it's a callable that receives the tarinfo object right before
it's added, so its uid/gid can be tweaked. This callable must return the
object. If it returns None, the object is not added to the tar file.
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.
TarInfo does not need set_uid() or set_gid() methods,
both can be set using the uid and gid attributes.
I was thinking about the set_ methods to be able to use
"root" (str) instead of "0" (int) for example, like
what the tar command seems to allow with --uid and --gid.
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.
Maybe we could add the "filter" option for 2.7/3.2 together with the
exclude option? And add a deprecation warning for "exclude" when it's
used, since it would then become *one* use case for "filter".
We could also add an exclude callable in the module, as an example
usage of the filter option, exactly like I did for shutil.copytree
(look for ignore_patterns).
I do not quite see the benefit from the set_* methods. Although the
attribute access I proposed may be slightly more complicated (because
you might need the pwd and grp modules) it offers the most freedom.
Let's take the set_uid() method as an example: Its purpose would be to
set both the uid and uname field in the tar header. That is fine as long
as its argument is a uid or username that actually exists. If set_uid()
gets a username that does not exist, what are we going to do? Only set
the uname field and leave the uid field alone or raise an exception? If
the user wants to set a non-existant username on purpose, he cannot use
the set_uid() method. And what are we going to do on Windows? Is there
anything comparable to pwd/grp we could use?
I expect the common use case for these both methods will be to *reset*
the owner information to a default, and this is done by setting uname to
"root" and uid to 0.
The filter argument is actually a nice idea. I have attached a patch
that outlines my idea of how it is supposed to be. Comments welcome.
I do not quite see the benefit from the set_* methods.
.. some explanations of the underlying complexity...
The only benefit I can see for the set_* method is to hide
the underlying complexity you've explained.
In Distutils, I'd like to provide a uid and gid option
to the sdist command where the user can set "root" for instance
and see the lib taking care of creating a tarfile with everything
set to the right value (and ignore the flags under windows etc)
So it seems that working per TarInfo is the wrong approach,
and a global function to create an archive would be better.
The filter argument is actually a nice idea. I have attached a
patch that outlines my idea of how it is supposed to be.