Repository navigation
fix: clean up cancelled URL downloads - #5
Conversation
Reviewer's GuideImplementationMake generated download filenames unique across concurrent runs by combining a timestamp with an atomic sequence.
Remove partial download files when cancellation interrupts either the direct download or fallback process.
Pass the fallback output path as an OS-native argument so non-UTF-8 paths are preserved.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/fetch.rs" line_range="154" />
<code_context>
result = downloader.download_audio_stream(&video, &name) => result,
- _ = cancelled(cancel) => return Err("cancelled".into()),
+ _ = cancelled(cancel) => {
+ let _ = std::fs::remove_file(&direct);
+ return Err("cancelled".into());
+ }
</code_context>
<issue_to_address>
**Active downloads lose their output**
When two fetches in the same process generate the same direct filename in the same millisecond and one is cancelled, `remove_file(&direct)` unlinks the shared path while the other downloader is writing it, so the active fetch fails or returns a missing or damaged audio file.
Give each fetch a unique direct output path and ensure cancellation only removes the path owned by that fetch.
</issue_to_address>
### Comment 2
<location path="src/fetch.rs" line_range="154" />
<code_context>
result = downloader.download_audio_stream(&video, &name) => result,
- _ = cancelled(cancel) => return Err("cancelled".into()),
+ _ = cancelled(cancel) => {
+ let _ = std::fs::remove_file(&direct);
+ return Err("cancelled".into());
+ }
</code_context>
<issue_to_address>
**Cancelled partials remain on Windows**
When cancellation wins while the direct download has the output file open on Windows, `remove_file` runs inside the cancellation branch while the losing download future can still hold the output file open. Windows rejects removing an open file, and the ignored error leaves the partial download behind after the future is dropped.
Have the select return a cancellation outcome, then remove `direct` after the select has completed and dropped the download future.
</issue_to_address>
### Comment 3
<location path="src/fetch.rs" line_range="154" />
<code_context>
result = downloader.download_audio_stream(&video, &name) => result,
- _ = cancelled(cancel) => return Err("cancelled".into()),
+ _ = cancelled(cancel) => {
+ let _ = std::fs::remove_file(&direct);
+ return Err("cancelled".into());
+ }
</code_context>
<issue_to_address>
**Fallback cancellation leaves partial audio**
When the direct downloader leaves a partial file before returning an error and cancellation occurs while yt-dlp is running, the direct download can return an error after leaving a partial file, then the fallback cancellation branch removes only `fallback` and returns. The abandoned direct partial remains in the audio directory.
Remove `direct` in the fallback cancellation branch before returning.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 3 findings to address first, and if cancellation wins while the downloader is finishing, the new cleanup can remove the completed file at the expected output path, and reverting would not restore it. The loss is limited to that download and can usually be repaired by downloading it again.
Blocking findings: src/fetch.rs:154, src/fetch.rs:154, src/fetch.rs:154
summary
validation
Summary by Sourcery
Ensure cancelled URL downloads remove temporary artifacts and reliably support arbitrary filesystem paths.
Bug Fixes:
Enhancements: