-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please support "numeric_owner" in tarfile #67382
Comments
Please consider adding a option to extract a tarfile with the uid/gid instead of the lookup for uname/gname in the tarheader (i.e. what tar --numeric-owner provides). One use-case is if you unpack a chroot tarfile that contains a /etc/{passwd,group} file with different uid/gid for user/groups like zope that may be present in both host and chroot but have different numbers. With the current approach files owned by this user will get the host uid/gid instead of the uid/gid of the chroot. Attached is a patch to outline what I have in mind - if there is a chance that this patch goes in I'm happy to write the required test (mocking os.chown()) for this to go in. Thanks for your consideration, |
"(...) if there is a chance that this patch goes in I'm happy to write the required test (mocking os.chown()) for this to go in." We don't accept changes without test. So you must write a test. Implementing the feature in Python makes sense. |
The patch also needs documentation update for TarFile.extract():
The tarfile documentation is located at Doc/library/tarfile.rst. |
I think Michael is asking if the proposed change would ever be accepted. If the answer is "no, not even if you write the tests and update the documentation", then there's no sense putting the work into this. That seems like a reasonable question to me. I think the proposed change is reasonable, but I'm no tarfile expert. But since this functionality is available in the tar command as --numeric-owner, I think the feature request itself is a good idea. |
I concur that this is a reasonable feature request, and it is not one that can be satisfied without modifying the tarfile module (that is, you can't write a simple wrapper to tarfile to get the functionality desired without cutting and pasting the entire chown method). |
I would argue that a serious alternative to this patch is to simply override the TarFile.chown() method in a subclass. However, I'm not sure if this expects too much of the user. |
If it weren't for the fact that this feature is something that the tar command provides, I'd agree (the chown method is relatively short). However, since tar *does* provide this feature, it seems reasonable for us to support it as well. Call me +0.5 :) |
I don't think we want to encourage the type of coupling that arises from subclassing, especially when when overriding an undocumented method. I'm +1 on the change. I'll review the patch. Michael: can you write the tests, and hopefully docs? |
Ignore my review comment on pwd and grp being None. I see that there is a test for it (at least grp), and they're not available on Windows. |
Thanks everyone for the comments and feedback! Attached is a updated patch with tests and a documentation update. Feedback is very welcome. I decided to skip the test on systems where root is not uid,gid=0. I could also mock that of course if you prefer it this way. Thanks, |
Updated patch with a few minor doc tweaks. The one substantive change I did make was to add numeric_owner to the call to self.chown() when setting directory owners. I believe this is correct, but I need to convince myself and to write a test. |
Note that this change will break code that subclasses TarFile and overrides chown(), as suggested in msg233915. I'm not too concerned about that, since chown() is not documented. Ideally it would be renamed to _chown(), but that's probably a separate issue. |
I added numeric_owner to the self.chown() call when adding directories. I'm reasonably sure this is correct. I added tests for dirs, although they need some cleaning up to be simpler and cleaner. I'll do that cleanup shortly, but I want to check this in before I get on a plane. I also changed the tests to use different numbers for .gid and .uid, in order to pick up if there's a transposition error somewhere. If anyone can test this on Windows, that would be helpful. |
Other than Misc/NEWS, I think this is the final version of this patch. |
|
Thanks for your review, Berker. I've updated the code with most of your suggestions, although some of them were mooted by some restructuring I did. A couple of questions/issues:
|
New changeset 6b70f16d585a by Eric V. Smith in branch 'default': |
Thanks everyone for their help, especially Michael for the original patch. |
New changeset e5a53d75dc19 by Zachary Ware in branch 'default': |
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
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: