Skip to content

Simplify downloads#4844

Open
djc wants to merge 12 commits intomainfrom
simplify-downloads
Open

Simplify downloads#4844
djc wants to merge 12 commits intomainfrom
simplify-downloads

Conversation

@djc
Copy link
Copy Markdown
Contributor

@djc djc commented May 3, 2026

No description provided.

@djc djc requested review from FranciscoTGouveia and rami3l May 3, 2026 20:39
@djc djc force-pushed the simplify-downloads branch from d6eef0e to 823dde3 Compare May 3, 2026 20:40
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 3, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rami3l rami3l self-assigned this May 3, 2026
@djc djc force-pushed the simplify-downloads branch from 823dde3 to 851139e Compare May 3, 2026 20:55
Comment thread src/cli/self_update.rs Outdated
Comment thread src/dist/download.rs
let download = Download::new(&url, &file, self.process).with_hasher(&mut hasher);

let download = match status {
Some(status) => download.with_status(status),
Copy link
Copy Markdown
Member

@rami3l rami3l May 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: A common builder trick is to let .with_foo() accept impl Into<Option<Foo>> so it can take foo, Some(foo) and None at the same time. Hopefully this way the chain can be more readable here 🙏

View changes since the review

Copy link
Copy Markdown
Contributor Author

@djc djc May 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure I love it. I like the added precision of the builder method exactly taking the thing (not the thing wrapped in Option), and I don't mind this boilerplate so much -- while it's more verbose, it still seems still pretty straightforward to understand.

Comment thread src/download/mod.rs Outdated
@djc djc force-pushed the simplify-downloads branch from 851139e to 92a68b8 Compare May 3, 2026 21:09
@djc djc force-pushed the simplify-downloads branch from 92a68b8 to cbd4f1e Compare May 3, 2026 21:10
Comment thread src/download/mod.rs Outdated
Comment on lines -170 to -173
&& let Some(h) = self.hasher.as_ref()
{
h.borrow_mut().update(data);
}
Copy link
Copy Markdown
Contributor

@FranciscoTGouveia FranciscoTGouveia May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the h.borrow_mut().update(data) call (previously inside the callback) moved elsewhere when the callback was removed, or is it no longer necessary?

The hasher is indeed initialized, via with_hasher(), but it does not appear to receive any bytes.
That said, shouldn't hash verification always fail?

View changes since the review

Comment thread src/download/mod.rs
if resume_from != 0 {
req = req.header(header::RANGE, format!("bytes={resume_from}-"));
}
let res = req.send().await.context("error downloading file")?;
Copy link
Copy Markdown
Contributor

@FranciscoTGouveia FranciscoTGouveia May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be .map_err(DownloadError::Reqwest) instead?

Previously, request() returned Result<Response, DownloadError>, so any reqwest::Error was automatically wrapped as DownloadError::Reqwest before being propagated.

As it stands, this change breaks the is_network_failure() function, and likely the network_failure_does_not_delete_partial_file test as well.
Without the wrapping, the error can no longer be downcast to DownloadError, causing is_network_failure to always return false, and thus, always removing partial files.

View changes since the review

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.

4 participants