From 5319e24d9f7b43dbfdfd368ea5ac467970061cd2 Mon Sep 17 00:00:00 2001 From: Namilskyy Date: Sat, 29 Nov 2025 20:48:12 +0300 Subject: Minor warnings fixed, implemented codeberg pages action --- src/net/http_packages.rs | 49 +++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'src/net/http_packages.rs') diff --git a/src/net/http_packages.rs b/src/net/http_packages.rs index 1e3c6ad..fe1833d 100644 --- a/src/net/http_packages.rs +++ b/src/net/http_packages.rs @@ -1,19 +1,21 @@ +use crate::cfg::config::Config; use reqwest; use std::fs::File; use std::io::Write; use std::path::Path; -use crate::cfg::config::Config; +#[allow(dead_code)] pub struct HTTPPackage { config: Config, } +#[allow(dead_code)] impl HTTPPackage { /// Creates a new Downloader object with the given configuration. /// /// # Arguments /// - /// * `config` - The full mesk + /// * `config` - The full mesk /// /// # Returns /// @@ -33,12 +35,11 @@ impl HTTPPackage { /// # Returns /// /// A new Config object with the parsed configuration. If there's an error while reading or parsing the file, returns an Err containing a Box. - pub fn parse_config(config_path: &str) -> Result> { + pub fn parse_config() -> Result> { let config = Config::parse()?; Ok(config) } - /// Downloads the INDEX.tar.gz file from the configured repository /// and stores it in the configured cache directory. /// @@ -58,11 +59,9 @@ impl HTTPPackage { let client = reqwest::Client::new(); - let response = client - .get(&index_url) - .send() - .await - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, format!("Request failed: {}", e)))?; + let response = client.get(&index_url).send().await.map_err(|e| { + std::io::Error::new(std::io::ErrorKind::Other, format!("Request failed: {}", e)) + })?; if !response.status().is_success() { return Err(std::io::Error::new( @@ -74,19 +73,35 @@ impl HTTPPackage { let index_data = response .bytes() .await - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, format!("Failed to read response body: {}", e)))? + .map_err(|e| { + std::io::Error::new( + std::io::ErrorKind::Other, + format!("Failed to read response body: {}", e), + ) + })? .to_vec(); let file_path = Path::new(cache_dir).join("INDEX.tar.gz"); - let mut file = File::create(&file_path) - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, format!("Failed to create file: {}", e)))?; - file.write_all(&index_data) - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, format!("Failed to write file: {}", e)))?; - file.flush() - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, format!("Failed to flush file: {}", e)))?; + let mut file = File::create(&file_path).map_err(|e| { + std::io::Error::new( + std::io::ErrorKind::Other, + format!("Failed to create file: {}", e), + ) + })?; + file.write_all(&index_data).map_err(|e| { + std::io::Error::new( + std::io::ErrorKind::Other, + format!("Failed to write file: {}", e), + ) + })?; + file.flush().map_err(|e| { + std::io::Error::new( + std::io::ErrorKind::Other, + format!("Failed to flush file: {}", e), + ) + })?; Ok(true) } } - -- cgit v1.2.3