-
Notifications
You must be signed in to change notification settings - Fork 23
Check for zero-length files before download; #22
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
base: main
Are you sure you want to change the base?
Conversation
…oid incomplete downloads If a file already exists but its size is zero, it is likely the result of a previous failed or interrupted download. This change ensures such files are deleted before attempting a new download, preventing the application from skipping incomplete files and improving download reliability.
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.
Pull Request Overview
This PR improves download reliability by checking for zero-length files that may result from failed or interrupted downloads. The changes ensure that empty files are removed before attempting a new download and that newly downloaded zero-length files are treated as failures.
- Added zero-length file detection and removal before downloading existing files
- Added validation after downloading to detect zero-length files and mark them as failures
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| if os.path.getsize(filepath) == 0: | ||
| os.remove(filepath) | ||
| else: | ||
| return True, True |
Copilot
AI
Aug 16, 2025
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 os.path.getsize() call can raise OSError if the file is deleted between the os.path.exists() check and this call, creating a race condition. Consider wrapping this in a try-except block or combining the existence and size checks.
| return True, True | |
| try: | |
| if os.path.getsize(filepath) == 0: | |
| os.remove(filepath) | |
| else: | |
| return True, True | |
| except OSError: | |
| # File may have been deleted or is inaccessible; proceed to download | |
| pass |
| if response.status == 200: | ||
| with open(filepath, 'wb') as f: | ||
| f.write(await response.read()) | ||
| if os.path.getsize(filepath) == 0: |
Copilot
AI
Aug 16, 2025
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 os.path.getsize() call can raise OSError if the file was not created successfully or was deleted by another process. This should be wrapped in a try-except block to handle potential file system errors.
| if os.path.getsize(filepath) == 0: | |
| try: | |
| if os.path.getsize(filepath) == 0: | |
| return False, False | |
| except OSError: |
Check for zero-length files before download; remove empty files to avoid incomplete downloads.
If a file already exists but its size is zero, it is likely the result of a previous failed or interrupted download. This change ensures such files are deleted before attempting a new download, preventing the application from skipping incomplete files and improving download reliability.