aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-core/src/package
diff options
context:
space:
mode:
Diffstat (limited to 'crates/mozart-core/src/package')
-rw-r--r--crates/mozart-core/src/package/archiver.rs4
-rw-r--r--crates/mozart-core/src/package/archiver/archive_manager.rs (renamed from crates/mozart-core/src/package/archiver/manager.rs)41
2 files changed, 23 insertions, 22 deletions
diff --git a/crates/mozart-core/src/package/archiver.rs b/crates/mozart-core/src/package/archiver.rs
index 142edbd..a01a173 100644
--- a/crates/mozart-core/src/package/archiver.rs
+++ b/crates/mozart-core/src/package/archiver.rs
@@ -5,8 +5,8 @@ use std::fs;
use std::io::Write as _;
use std::path::{Path, PathBuf};
-pub mod manager;
-pub use manager::{ArchiveManager, ArchivePackage};
+mod archive_manager;
+pub use archive_manager::*;
/// A compiled exclude pattern derived from a gitignore-style rule.
pub struct ExcludePattern {
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)?,