From f8b9506be25332f8772fca44c1cf7106caeea3fe Mon Sep 17 00:00:00 2001 From: Namilskyy Date: Sun, 30 Nov 2025 17:16:54 +0300 Subject: Fixed all clippy warnings --- src/pkgtoolkit/pkgtools.rs | 69 +++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 40 deletions(-) (limited to 'src/pkgtoolkit') diff --git a/src/pkgtoolkit/pkgtools.rs b/src/pkgtoolkit/pkgtools.rs index 8198624..877c8c8 100644 --- a/src/pkgtoolkit/pkgtools.rs +++ b/src/pkgtoolkit/pkgtools.rs @@ -8,7 +8,6 @@ use std::{ path::Path, process::Command, str, - collections::HashMap }; // use emissary_core::i2np::tunnel::build; @@ -38,7 +37,7 @@ pub struct Package { } #[derive(Deserialize, Debug, Clone)] -pub struct Install_meta { +pub struct InstallMeta { path: String, user: String, group: String, @@ -51,7 +50,7 @@ pub struct Install_meta { #[derive(Deserialize, Debug, Clone)] struct Install { package: Package, - install: Install_meta, + install: InstallMeta, } #[allow(dead_code)] @@ -102,9 +101,8 @@ impl Package { /// Returns an error if the build command fails. fn execute_build(&self, build_meta: &Build) -> Result<(), std::io::Error> { let config = Config::parse() - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; - let build_dir = - Path::new(&config.paths.cache_dir).join(format!("{}-{}", self.name, self.version)); + .map_err(|e| std::io::Error::other(e.to_string()))?; + let build_dir = Path::new(&config.paths.cache_dir).join(format!("{}-{}", self.name, self.version)); let mut cmd = match build_meta.build_system { BuildSystems::Make => { @@ -142,16 +140,14 @@ impl Package { }; let output = cmd.output().map_err(|e| { - std::io::Error::new( - std::io::ErrorKind::Other, + std::io::Error::other( format!("Build command failed: {}", e), ) })?; if !output.status.success() { let stderr = String::from_utf8_lossy(&output.stderr); - return Err(std::io::Error::new( - std::io::ErrorKind::Other, + return Err(std::io::Error::other( format!("Build failed:\n{}", stderr), )); } @@ -197,6 +193,7 @@ impl Package { /// /// Returns an error if the `cache_dir` cannot be created, if the required 'INSTALL' file /// is not found, or if the 'INSTALL' file is empty. + #[allow(clippy::type_complexity)] fn loadmeta( minimal_package_meta: &mut Self, ) -> Result<(Install, Option, Option), Box> { @@ -388,35 +385,35 @@ impl Package { // BUILD NOT EMPTY. SOURCE: -> BUILD -> INSTALL -> SETTS // BUILD EMPTY. BIN: -> INSTALL -> SETTS enum Strategies { - BIN, - SOURCE, + Bin, + Source, } let strategy; //default if build_meta.is_none() { log::info!("BUILD file is empty. Skipping build, preparing to install"); - strategy = Strategies::BIN; + strategy = Strategies::Bin; } else { - strategy = Strategies::SOURCE; + strategy = Strategies::Source; log::info!("BUILD file is not empty. Skipping install, preparing to build"); } match strategy { - Strategies::BIN => { + Strategies::Bin => { if install_meta.install.custom_script.is_none() { log::info!("Strategy: BIN; No custom script. Running default install hook."); } else { log::info!("Strategy: BIN; Running custom script."); let script = install_meta.install.custom_script.as_ref().unwrap(); if !script.starts_with("./") { - let _output = std::process::Command::new(format!("{}", script)); + let _output = std::process::Command::new(script); } else { let _output = std::process::Command::new(format!("/bin/sh '{}'", script)); } } } - Strategies::SOURCE => { + Strategies::Source => { log::info!("Strategy: SOURCE; Running default build hook."); let _ = self.execute_build(&build_meta.unwrap()); } @@ -437,9 +434,9 @@ impl Package { /// Returns an error if the BUILD file is invalid or if the build or install hook fails. pub fn install(&mut self) -> Result { let config = Config::parse() - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + .map_err(|e| std::io::Error::other( e.to_string()))?; let (install_meta, _setts_meta, build_meta) = Self::loadmeta(self) - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + .map_err(|e| std::io::Error::other(e.to_string()))?; let is_build_present_and_not_empty = build_meta.is_some(); @@ -460,16 +457,14 @@ impl Package { .current_dir(&build_dir) .output() .map_err(|e| { - std::io::Error::new( - std::io::ErrorKind::Other, + std::io::Error::other( format!("'make install' failed: {}", e), ) })?; if !output.status.success() { let stderr = String::from_utf8_lossy(&output.stderr); - return Err(std::io::Error::new( - std::io::ErrorKind::Other, + return Err(std::io::Error::other( format!("'make install' failed:\n{}", stderr), )); } @@ -490,15 +485,13 @@ impl Package { Command::new(script).status() } .map_err(|e| { - std::io::Error::new( - std::io::ErrorKind::Other, + std::io::Error::other( format!("Failed to run custom script: {}", e), ) })?; if !status.success() { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, + return Err(std::io::Error::other( "Custom install script failed", )); } @@ -507,27 +500,22 @@ impl Package { "No custom script. Running default install hook for {}", install_meta.package.name ); - // --- Дефолтный хук установки --- - // 1. Копируем файл из build_dir (предположим, что бинарный файл лежит в корне распакованного архива) - let source_file_name = &self.name; // Предполагаем имя файла = имя пакета + let source_file_name = &self.name; let build_dir = Path::new(&config.paths.cache_dir) .join(format!("{}-{}", self.name, self.version)); let src_path = build_dir.join(source_file_name); let dest_path = Path::new(&install_meta.install.path); - // Убедимся, что целевая директория существует if let Some(parent) = dest_path.parent() { create_dir_all(parent).map_err(|e| { - std::io::Error::new( - std::io::ErrorKind::Other, + std::io::Error::other( format!("Failed to create parent dir: {}", e), ) })?; } fs::copy(&src_path, dest_path).map_err(|e| { - std::io::Error::new( - std::io::ErrorKind::Other, + std::io::Error::other( format!("Failed to copy file: {}", e), ) })?; @@ -540,19 +528,20 @@ impl Package { })?; let perms = PermissionsExt::from_mode(mode); fs::set_permissions(dest_path, perms).map_err(|e| { - std::io::Error::new( - std::io::ErrorKind::Other, + std::io::Error::other( format!("Failed to set permissions: {}", e), ) })?; let output = Command::new("chown") - .arg(&format!("{}:{}", install_meta.install.user, install_meta.install.group)) + .arg(format!( + "{}:{}", + install_meta.install.user, install_meta.install.group + )) .arg(dest_path) .output() .map_err(|e| { - std::io::Error::new( - std::io::ErrorKind::Other, + std::io::Error::other( format!("'chown' command failed: {}", e), ) })?; -- cgit v1.2.3