summaryrefslogtreecommitdiff
path: root/src/net/http_package.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/http_package.rs')
-rw-r--r--src/net/http_package.rs37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/net/http_package.rs b/src/net/http_package.rs
index d31cc90..4566e05 100644
--- a/src/net/http_package.rs
+++ b/src/net/http_package.rs
@@ -12,6 +12,10 @@ use std::{collections::HashMap, path::Path};
use tar::Archive;
use tokio::{fs::File, io::AsyncWriteExt};
+use crate::pkgtoolkit::install::InstallOperations;
+use crate::pkgtoolkit::archive::ArchiveOperations;
+
+
pub struct HTTPPackage {
pub config: Config,
pub index_packages: Option<HashMap<String, Package>>,
@@ -143,7 +147,10 @@ impl HTTPPackage {
let mut package_map = HashMap::new();
for pkg in index_data.packages {
- let base_url = url::Url::parse(&self.config.repo.repo_url)?;
+ let base_url = match &self.config.repo.repo_http_url {
+ Some(url) => url::Url::parse(url)?,
+ None => url::Url::parse(&self.config.repo.repo_url)?,
+ };
let full_url = base_url.join(&pkg.url)?;
let mut pkg_clone = pkg.clone();
pkg_clone.url = full_url.to_string();
@@ -227,12 +234,13 @@ impl HTTPPackage {
/// Fetches a specific package identified by `package_name`.
/// Assumes `fetch_index_http` has been called and `self.index_packages` is populated to get the URL.
- /// Downloads the package file (.mesk) to the cache directory with a progress bar.
+ /// Downloads the package file (.mesk) to the cache directory with a progress bar,
+ /// extracts it, and installs the package.
///
/// # Errors
///
/// Returns an error if the index is not loaded, the package is not found in the index,
- /// the package URL is invalid, the request fails, or if there's an issue writing the file.
+ /// the package URL is invalid, the request fails, extraction fails, or installation fails.
pub async fn fetch_package_http(
&self,
package_name: &str,
@@ -259,7 +267,28 @@ impl HTTPPackage {
package_name,
file_path
);
- Ok(true)
+
+ // Extract the package archive
+ log::info!("Extracting package archive for '{}'...", package_name);
+ Package::extract_archive(&file_path.to_string_lossy())
+ .map_err(|e| format!("Failed to extract package archive: {}", e))?;
+
+ log::info!("Package archive extracted successfully.");
+
+ // Install the package
+ log::info!("Installing package '{}'...", package_name);
+ let mut package = package_info.clone();
+
+ match package.install() {
+ Ok(_) => {
+ log::info!("Package '{}' installed successfully.", package_name);
+ Ok(true)
+ }
+ Err(e) => {
+ log::error!("Failed to install package '{}': {}", package_name, e);
+ Err(format!("Installation failed: {}", e).into())
+ }
+ }
}
/// Fetches a specific package identified by `index` (likely the package name).