Skip to content
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

Fix tar: invalid magic error when running add_version #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gyf9835
Copy link

@gyf9835 gyf9835 commented Nov 24, 2024

fix #86 (comment)

Problem Description

When downloading and saving a file, running the tar command to extract it occasionally fails with the following errors:

tar: invalid magic  
tar: short read  
This issue occurs even with small files (e.g., 66 KB).

Cause Analysis

Python’s file I/O uses a buffered mechanism, meaning f.write() may temporarily store data in memory without immediately writing it to the filesystem.
If tar attempts to extract the file before the data is fully written, it may read an incomplete or corrupted file, causing the extraction to fail.
The issue is more likely to occur in high-load environments or with delayed disk I/O.
Solution
Add f.flush() immediately after f.write() to ensure the file buffer is flushed to the operating system before invoking the tar command. This guarantees the file is fully written and ready for further operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

failed to deploy on remote server
1 participant