-
-
Notifications
You must be signed in to change notification settings - Fork 769
feat(lock): add resolve_lock_info to core backends for checksum fetching #7180
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
Changes from 1 commit
b533ed6
6a4b2f2
925f35e
315e484
852f661
9ed8e4e
6054946
13b50f8
733c67f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,7 @@ | ||||||
| use std::collections::HashMap; | ||||||
| use std::io::Write; | ||||||
| use std::path::Path; | ||||||
| use std::sync::{Arc, Mutex}; | ||||||
| use std::time::Duration; | ||||||
|
|
||||||
| use base64::Engine; | ||||||
|
|
@@ -9,6 +11,7 @@ use regex::Regex; | |||||
| use reqwest::header::{HeaderMap, HeaderValue}; | ||||||
| use reqwest::{ClientBuilder, IntoUrl, Method, Response}; | ||||||
| use std::sync::LazyLock as Lazy; | ||||||
| use tokio::sync::OnceCell; | ||||||
| use tokio_retry::Retry; | ||||||
| use tokio_retry::strategy::{ExponentialBackoff, jitter}; | ||||||
| use url::Url; | ||||||
|
|
@@ -36,6 +39,14 @@ pub static HTTP_FETCH: Lazy<Client> = Lazy::new(|| { | |||||
| .unwrap() | ||||||
| }); | ||||||
|
|
||||||
| /// In-memory cache for HTTP text responses, useful for requests that are repeated | ||||||
| /// during a single operation (e.g., fetching SHASUMS256.txt for multiple platforms). | ||||||
| /// Each URL gets its own OnceCell to ensure concurrent requests for the same URL | ||||||
| /// wait for the first fetch to complete rather than all fetching simultaneously. | ||||||
| type CachedResult = Arc<OnceCell<Result<String, String>>>; | ||||||
| static HTTP_CACHE: Lazy<Mutex<HashMap<String, CachedResult>>> = | ||||||
| Lazy::new(|| Mutex::new(HashMap::new())); | ||||||
|
|
||||||
| #[derive(Debug)] | ||||||
| pub struct Client { | ||||||
| reqwest: reqwest::Client, | ||||||
|
|
@@ -133,6 +144,39 @@ impl Client { | |||||
| Ok(text) | ||||||
| } | ||||||
|
|
||||||
| /// Like get_text but caches results in memory for the duration of the process. | ||||||
| /// Useful when the same URL will be requested multiple times (e.g., SHASUMS256.txt | ||||||
| /// when locking multiple platforms). Concurrent requests for the same URL will | ||||||
| /// wait for the first fetch to complete. | ||||||
| pub async fn get_text_cached<U: IntoUrl>(&self, url: U) -> Result<String> { | ||||||
| let url = url.into_url().unwrap(); | ||||||
| let key = url.to_string(); | ||||||
|
|
||||||
| // Get or create the OnceCell for this URL | ||||||
| let cell = { | ||||||
| let mut cache = HTTP_CACHE.lock().unwrap(); | ||||||
|
||||||
| let mut cache = HTTP_CACHE.lock().unwrap(); | |
| let mut cache = HTTP_CACHE.lock().expect("Failed to lock HTTP_CACHE mutex (possibly poisoned)"); |
Copilot
AI
Dec 4, 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 HashMap uses String keys which requires cloning the URL string. Consider using Arc<str> or a reference-counted key to avoid string clones on cache hits.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,6 +50,13 @@ pub struct PlatformInfo { | |||||||||||
| pub url_api: Option<String>, | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| impl PlatformInfo { | ||||||||||||
| /// Returns true if this PlatformInfo has no meaningful data (for serde skip) | ||||||||||||
| pub fn is_empty(&self) -> bool { | ||||||||||||
| self.checksum.is_none() && self.url.is_none() && self.url_api.is_none() | ||||||||||||
|
||||||||||||
| self.checksum.is_none() && self.url.is_none() && self.url_api.is_none() | |
| self.checksum.is_none() | |
| && self.size.is_none() | |
| && self.url.is_none() | |
| && self.url_api.is_none() |
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.
Using
unwrap()here will panic on invalid URLs without a helpful error message. Consider using?operator to propagate the error with proper context, or provide a descriptive error message.