Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I694da71afe93bcb33687ff7d8e75f04f6a6a6964
49 lines
1.5 KiB
Rust
49 lines
1.5 KiB
Rust
use std::path::{Path, PathBuf};
|
|
|
|
use crate::{
|
|
cli::FetchArgs,
|
|
error::Result,
|
|
fetch::Fetcher,
|
|
ipc::{IpcCoordinator, OperationGuard, OperationType},
|
|
model::{Config, LockFile},
|
|
};
|
|
|
|
pub async fn execute(
|
|
args: FetchArgs,
|
|
lockfile_path: &Path,
|
|
config_path: &Path,
|
|
) -> Result<()> {
|
|
// Load expects directory path, so get parent directory
|
|
let lockfile_dir = lockfile_path.parent().unwrap_or(Path::new("."));
|
|
let config_dir = config_path.parent().unwrap_or(Path::new("."));
|
|
|
|
let lockfile = LockFile::load(lockfile_dir)?;
|
|
let config = Config::load(config_dir)?;
|
|
|
|
// Create IPC coordinator for this modpack
|
|
let working_dir = PathBuf::from(".");
|
|
let coordinator = IpcCoordinator::new(&working_dir)?;
|
|
|
|
// Check for conflicting operations
|
|
if coordinator.has_running_operation(OperationType::Fetch) {
|
|
// Wait for conflicting operations to complete with timeout
|
|
let timeout = std::time::Duration::from_secs(args.timeout.unwrap_or(300));
|
|
coordinator
|
|
.wait_for_conflicts(OperationType::Fetch, timeout)
|
|
.await?;
|
|
}
|
|
|
|
// Register this fetch operation
|
|
let operation_id = coordinator.register_operation(OperationType::Fetch)?;
|
|
let _guard = OperationGuard::new(coordinator, operation_id);
|
|
|
|
// Create fetcher with shelve option
|
|
let fetcher = Fetcher::new(".").with_shelve(args.shelve);
|
|
|
|
// Fetch all projects (progress indicators handled in fetch.rs)
|
|
fetcher.fetch_all(&lockfile, &config).await?;
|
|
|
|
println!("Fetch complete");
|
|
|
|
Ok(())
|
|
}
|