aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-registry
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-02-24 01:00:48 +0900
committernsfisis <nsfisis@gmail.com>2026-02-24 01:00:48 +0900
commit64ed53cf184fb05cbfe9f0336bc8695ff0e800f8 (patch)
treecea8c1854c5c7bf0fcffcaf175f1bf188d9f8904 /crates/mozart-registry
parentd9858fbd322ce20de84f44ce67ae11edf081578c (diff)
downloadphp-mozart-64ed53cf184fb05cbfe9f0336bc8695ff0e800f8.tar.gz
php-mozart-64ed53cf184fb05cbfe9f0336bc8695ff0e800f8.tar.zst
php-mozart-64ed53cf184fb05cbfe9f0336bc8695ff0e800f8.zip
fix(cache): enable dist archive caching for all commands
files_cache was Option<&Cache> and install_from_lock always passed None, so downloaded zip/tar archives were never cached. Make the parameter non-optional (&Cache) and wire it through every command that downloads dist archives (install, update, require, remove, create-project, archive). The Cache internally respects --no-cache via its enabled flag, so the Option wrapper was unnecessary. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart-registry')
-rw-r--r--crates/mozart-registry/src/downloader.rs18
1 files changed, 7 insertions, 11 deletions
diff --git a/crates/mozart-registry/src/downloader.rs b/crates/mozart-registry/src/downloader.rs
index 6660188..5431360 100644
--- a/crates/mozart-registry/src/downloader.rs
+++ b/crates/mozart-registry/src/downloader.rs
@@ -77,22 +77,20 @@ impl DownloadProgress {
/// If `expected_shasum` is provided and non-empty, verifies SHA-1 of the downloaded bytes.
/// If `progress` is provided, increments it as bytes are received and sets the total from
/// the `Content-Length` response header.
-/// If `files_cache` is provided, the downloaded bytes are cached by URL; cache hits skip
-/// the network request entirely.
+/// Downloaded bytes are cached by URL in `files_cache`; cache hits skip the network request
+/// entirely.
#[tracing::instrument(skip(expected_shasum, progress, files_cache))]
pub async fn download_dist(
url: &str,
expected_shasum: Option<&str>,
progress: Option<&mut DownloadProgress>,
- files_cache: Option<&Cache>,
+ files_cache: &Cache,
) -> anyhow::Result<Vec<u8>> {
// Build a cache key from the URL
let cache_key = Cache::sanitize_key(url);
// Check cache first
- if let Some(cache) = files_cache
- && let Some(cached_bytes) = cache.read_bytes(&cache_key)
- {
+ if let Some(cached_bytes) = files_cache.read_bytes(&cache_key) {
// Verify checksum against cache hit if provided
if let Some(shasum) = expected_shasum
&& !shasum.is_empty()
@@ -158,9 +156,7 @@ pub async fn download_dist(
}
// Write to cache
- if let Some(cache) = files_cache {
- let _ = cache.write_bytes(&cache_key, &bytes);
- }
+ let _ = files_cache.write_bytes(&cache_key, &bytes);
Ok(bytes)
}
@@ -328,7 +324,7 @@ pub fn extract_tar_gz(data: &[u8], target_dir: &Path) -> anyhow::Result<()> {
/// - `vendor_dir`: path to `vendor/` directory
/// - `package_name`: e.g. `"monolog/monolog"`
/// - `progress`: optional mutable progress tracker to update during download
-/// - `files_cache`: optional files cache; if provided, the archive bytes are cached by URL
+/// - `files_cache`: files cache; archive bytes are cached by URL
pub async fn install_package(
dist_url: &str,
dist_type: &str,
@@ -336,7 +332,7 @@ pub async fn install_package(
vendor_dir: &Path,
package_name: &str,
progress: Option<&mut DownloadProgress>,
- files_cache: Option<&Cache>,
+ files_cache: &Cache,
) -> anyhow::Result<()> {
let target = vendor_dir.join(package_name);