Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upbpo-18819: tarfile: only set device fields for device files #18080
Conversation
The GNU docs describe the `devmajor` and `devminor` fields of the tar header struct only in the context of character and block special files, suggesting that in other cases they are not populated. Typical utilities behave accordingly; this patch teaches `tarfile` to do the same. Test Plan: No tests added because none appear to exist for this module. Manually verified that this enables output that is bit-for-bit compatible with GNU tar. In particular, this program now passes on my Ubuntu 16.04, whereas it failed before this patch: ```python import os import subprocess import tarfile import tempfile filename = "important_data" contents = b"The quick brown fox jumps over the lazy dog" with tempfile.TemporaryDirectory() as tmpdir: os.chdir(tmpdir) with open(filename, "wb") as outfile: outfile.write(contents) with tarfile.open("py.tar", "x", format=tarfile.GNU_FORMAT) as outfile: outfile.add(filename) subprocess.check_call(["tar", "cf", "gnu.tar", filename]) subprocess.check_call(["shasum", "-a", "256", "py.tar", "gnu.tar"]) subprocess.check_call(["cmp", "-b", "py.tar", "gnu.tar"]) ``` (The exact hashes depend on the calling user and current time but should always be the same across both output archives.) wchargin-branch: tarfile-limit-device-headers
This comment has been minimized.
This comment has been minimized.
The code looks good. Question, though: why use both Also, the tests for |
This looks good. Add your test and we should be ready to commit. |
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Jan 22, 2020
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Yes; I had the
Great, thanks. Not sure how I missed this.
Will add a test to Thanks for the speedy review! I’ll add a test and get back to you. |
Test Plan: This passes as written, and fails if the previous commit is reverted. wchargin-branch: tarfile-limit-device-headers
This comment has been minimized.
This comment has been minimized.
I’ve put the test in a new test class because it needs to run only in I have made the requested changes; please review again. |
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Jan 22, 2020
Thanks for making the requested changes! @ethanfurman: please review the changes made to this pull request. |
Looking good. Nice tests. Please add yourself to Misc/ACKS and we should be good to go. (Sorry for not noticing that earlier.) |
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Jan 23, 2020
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
(Per request of Ethan Furman.) wchargin-branch: tarfile-limit-device-headers
This comment has been minimized.
This comment has been minimized.
Done; thanks! I have made the requested changes; please review again. |
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Jan 23, 2020
Thanks for making the requested changes! @ethanfurman: please review the changes made to this pull request. |
wchargin commentedJan 20, 2020
•
edited
The GNU docs describe the
devmajor
anddevminor
fields of the tarheader struct only in the context of character and block special files,
suggesting that in other cases they are not populated. Typical utilities
behave accordingly; this patch teaches
tarfile
to do the same.Test Plan:
Unit tests added; they fail before this commit and pass after it. Also
verified that this enables output that is bit-for-bit compatible with
GNU
tar
. In particular, this program now passes on my Ubuntu 16.04,whereas it failed before this patch:
(The exact contents of the files depend on the calling user and current
time, but should always be the same across both output archives.)
wchargin-branch: tarfile-limit-device-headers
https://bugs.python.org/issue18819