Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35843 > unrolled thread
| Started by | lars@gustaebel.de |
|---|---|
| First post | 2012-12-31 09:47 +0100 |
| Last post | 2012-12-31 09:47 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Tarfile and usernames lars@gustaebel.de - 2012-12-31 09:47 +0100
| From | lars@gustaebel.de |
|---|---|
| Date | 2012-12-31 09:47 +0100 |
| Subject | Re: Tarfile and usernames |
| Message-ID | <mailman.1493.1356944398.29569.python-list@python.org> |
On Sun, Dec 30, 2012 at 03:07:05PM -0500, Albert Hopkins wrote:
> > I can't see documented anywhere what this library does with userids and
> > groupids. I can't guarantee that the computers involved will have the
> > same users and groups, and would like the archives to be extracted so
> > that the files are all owned by the extracting user.
> However, it should be stated that by default (on *nix anyway) if the
> user is not root then user/groups are assigned to the user exctracting
> the file (because only root can assign userids/non-member-groups).
> The TarFile extract*() methods pretty much inherit the same behavior as
> the *nix tar command. So if you are extracting as a non-root user, you
> should expect the same behavoir. If you are extracting as root but
> don't want to change user/groups may have to extract it manually or
> create your own class by inheriting TarFile and overriding the .chown()
> method.
Please take a look at the second example in the Examples section of the tarfile
docs:
http://docs.python.org/2.7/library/tarfile.html#examples
It shows how to extract a subset of an archive using a generator as some kind
of filter for the extractall() method. Just rewrite the example so that every
tarinfo is patched with the required user and group name information before
being yielded:
def filter(members):
for tarinfo in members:
tarinfo.uname = "root"
tarinfo.gname = "root"
yield tarinfo
That's it.
--
Lars Gustäbel
lars@gustaebel.de
Back to top | Article view | comp.lang.python
csiph-web