-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-12800: 'tarfile.StreamError: seeking backwards is not allowed' when extract symlink #13217
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
Conversation
module in stream mode ('r|') fails with an exception when a file or symlink of the same name already exists. The fix is to remove the existing file or symlink before extraction. Tests are included.
Is there a way I can help get this landed? I just ran into this today and wasted a lot of time trying to figure out why my tar file opened in streaming mode was trying to seek backwards. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of removing the file / symlink before creating the symlink looks good to me, GNU tar behave the same way.
Please note that GNU tar also removes an empty directory if it exists (but keeps a non-empty directory, and give an error), we may want to copy this too?
|
||
@support.skip_unless_symlink | ||
def test_overwrite_symlink(self): | ||
tmpdir = support.temp_cwd('overwrite_symlink') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
temp_cwd is a context manager, please use it in a with statement (also you're not using the variable at all which is strange).
finally: | ||
try: | ||
os.unlink(link) | ||
except: | ||
pass | ||
|
||
try: | ||
os.unlink(source) | ||
except: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If using a temporary directory for your test (temp_cwd in a context manager for example), you should not need this at all.
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 |
I've submitted a new PR with the suggested changes: #20972 I have made the requested changes; please review again. |
Thanks for the PR, @websurfer5, but I'm closing this in favor of PR GH-21409, which restores the original fix for this issue which was lost in a bad merge. |
Extracting a symlink from a tarball using the tarfile
module in stream mode ('r|') fails with an exception when a file
or symlink of the same name already exists. The fix is to remove
the existing file or symlink before extraction. Tests are included.
https://bugs.python.org/issue12800