Skip to content

Conversation

@hyzboy
Copy link

@hyzboy hyzboy commented Aug 16, 2025

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.

…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.
Copilot AI review requested due to automatic review settings August 16, 2025 04:59
Copy link

Copilot AI left a 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
Copy link

Copilot AI Aug 16, 2025

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
if response.status == 200:
with open(filepath, 'wb') as f:
f.write(await response.read())
if os.path.getsize(filepath) == 0:
Copy link

Copilot AI Aug 16, 2025

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.

Suggested change
if os.path.getsize(filepath) == 0:
try:
if os.path.getsize(filepath) == 0:
return False, False
except OSError:

Copilot uses AI. Check for mistakes.
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.

1 participant