aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-core/src/package/archiver
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-10 23:58:26 +0900
committernsfisis <nsfisis@gmail.com>2026-05-10 23:58:26 +0900
commit8871b923fa3df1935c263db155cb8bc3d59705cd (patch)
tree4c080d383c30a0d92229f9b411f1d94976a6e707 /crates/mozart-core/src/package/archiver
parent59bab6efee41a196b0d9d392167c536abbe068ba (diff)
downloadphp-mozart-8871b923fa3df1935c263db155cb8bc3d59705cd.tar.gz
php-mozart-8871b923fa3df1935c263db155cb8bc3d59705cd.tar.zst
php-mozart-8871b923fa3df1935c263db155cb8bc3d59705cd.zip
refactor(downloader): turn DownloadManager into downloader registry
Reshape DownloadManager from a hard-coded VCS match into a registry of DownloaderInterface instances keyed by source type, mirroring Composer's DownloadManager — with prefer-source/dist preferences, an IO handle, and a files cache. ArchiveManager now resolves dist sources through a shared DownloadManager instead of calling download_dist directly, and Composer::require / try_load take an IO so it flows through the factory wiring.
Diffstat (limited to 'crates/mozart-core/src/package/archiver')
-rw-r--r--crates/mozart-core/src/package/archiver/archive_manager.rs (renamed from crates/mozart-core/src/package/archiver/manager.rs)41
1 files changed, 21 insertions, 20 deletions
diff --git a/crates/mozart-core/src/package/archiver/manager.rs b/crates/mozart-core/src/package/archiver/archive_manager.rs
index bd5083e..b4f8e27 100644
--- a/crates/mozart-core/src/package/archiver/manager.rs
+++ b/crates/mozart-core/src/package/archiver/archive_manager.rs
@@ -1,3 +1,5 @@
+use crate::downloader::DownloadManager;
+
use super::{
ArchiveFormat, collect_archivable_files, create_archive, generate_archive_filename,
parse_composer_excludes, parse_gitattributes, parse_gitignore_pattern, self_exclusion_patterns,
@@ -108,20 +110,22 @@ fn read_archive_config(composer_json_path: &Path) -> anyhow::Result<(Option<Stri
Ok((name, excludes))
}
-/// Manages the creation of package archives.
-///
-/// Mirrors Composer's `Composer\Package\Archiver\ArchiveManager`.
-pub struct ArchiveManager;
+trait ArchiverInterface: Send + Sync {}
-impl Default for ArchiveManager {
- fn default() -> Self {
- Self::new()
- }
+/// ref: \Composer\Package\Archiver\ArchiveManager
+pub struct ArchiveManager {
+ download_manager: std::sync::Arc<tokio::sync::Mutex<DownloadManager>>,
+ _archivers: Vec<Box<dyn ArchiverInterface>>,
+ _overwrite_files: bool,
}
impl ArchiveManager {
- pub fn new() -> Self {
- ArchiveManager
+ pub fn new(download_manager: std::sync::Arc<tokio::sync::Mutex<DownloadManager>>) -> Self {
+ Self {
+ download_manager,
+ _archivers: Vec::new(),
+ _overwrite_files: true,
+ }
}
/// Build the parts that make up a package archive's filename.
@@ -170,7 +174,6 @@ impl ArchiveManager {
target_dir: &Path,
file_name: Option<&str>,
ignore_filters: bool,
- files_cache: &crate::repository::cache::Cache,
) -> anyhow::Result<PathBuf> {
let archive_format = ArchiveFormat::parse(format).ok_or_else(|| {
anyhow::anyhow!(
@@ -179,7 +182,7 @@ impl ArchiveManager {
)
})?;
- let source = acquire_source(package, files_cache).await?;
+ let source = acquire_source(package, &self.download_manager).await?;
let filename_base = if let Some(file_name) = file_name {
file_name.to_string()
@@ -228,7 +231,7 @@ impl ArchiveManager {
/// composer.json.
async fn acquire_source(
package: &ArchivePackage,
- files_cache: &crate::repository::cache::Cache,
+ download_manager: &std::sync::Arc<tokio::sync::Mutex<DownloadManager>>,
) -> anyhow::Result<AcquiredSource> {
match package {
ArchivePackage::Root { source_dir, .. } => {
@@ -262,13 +265,11 @@ async fn acquire_source(
let temp_dir = temp_base.join(&unique);
std::fs::create_dir_all(&temp_dir)?;
- let bytes = crate::repository::downloader::download_dist(
- dist_url,
- dist_shasum.as_deref(),
- None,
- files_cache,
- )
- .await?;
+ let bytes = download_manager
+ .lock()
+ .await
+ .download_legacy(dist_url, dist_shasum.as_deref(), None)
+ .await?;
match dist_type.as_str() {
"zip" => crate::repository::downloader::extract_zip(&bytes, &temp_dir)?,