From 1a71848be0f54459117ed74d7b7e084fbe1a123e Mon Sep 17 00:00:00 2001 From: Pauline Date: Sat, 11 May 2024 06:31:44 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20chore(core):=20apply=20cargo=20c?= =?UTF-8?q?lippy=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/api/cluster/mod.rs | 20 ++++++++------------ core/src/api/java.rs | 4 ++-- core/src/api/logger.rs | 8 ++++---- core/src/api/package/import/mod.rs | 20 +++++++++----------- core/src/api/proxy/mod.rs | 2 +- core/src/lib.rs | 2 +- core/src/store/clusters.rs | 4 ++-- core/src/store/credentials.rs | 10 +++++----- core/src/store/dirs.rs | 2 +- core/src/store/minecraft.rs | 1 - core/src/store/package.rs | 10 +++++----- core/src/store/processor.rs | 6 ++++++ core/src/utils/io.rs | 8 ++++---- 13 files changed, 48 insertions(+), 49 deletions(-) diff --git a/core/src/api/cluster/mod.rs b/core/src/api/cluster/mod.rs index 54accfef..494c6437 100644 --- a/core/src/api/cluster/mod.rs +++ b/core/src/api/cluster/mod.rs @@ -2,27 +2,23 @@ //! //! API for our managed Minecraft instances, Clusters. -use crate::proxy::send::{init_ingress, send_cluster, send_ingress}; -use crate::proxy::utils::ingress_try_for_each; -use crate::proxy::{ClusterPayloadType, IngressType}; +use crate::proxy::send::send_cluster; + +use crate::proxy::ClusterPayloadType; use crate::store::ProcessorChild; // use crate::package::from::{EnvType, PackDependency, PackFile, PackFileHash, PackFormat}; use crate::prelude::{ClusterPath, JavaVersion, PackagePath}; pub use crate::store::{Cluster, JavaOptions, State}; -use crate::store::{InnerPathLinux, MinecraftCredentials, PackageMetadata, PackageSide}; -use crate::utils::http; +use crate::store::MinecraftCredentials; + use crate::utils::io::{self, IOError}; -use async_zip::tokio::write::ZipFileWriter; -use async_zip::{Compression, ZipEntryBuilder}; -use serde_json::json; - -use std::collections::{HashMap, HashSet}; +use std::collections::{HashMap}; use std::future::Future; -use std::iter::FromIterator; + use std::path::{Path, PathBuf}; use std::sync::Arc; -use tokio::fs::File; + use tokio::io::AsyncReadExt; use tokio::process::Command; use tokio::sync::RwLock; diff --git a/core/src/api/java.rs b/core/src/api/java.rs index 0ea9c1ec..b6b03e21 100644 --- a/core/src/api/java.rs +++ b/core/src/api/java.rs @@ -67,7 +67,7 @@ pub async fn install_java(java_version: u32) -> crate::Result { let path = state.directories.java_dir().await; let mut archive = zip::ZipArchive::new(std::io::Cursor::new(file)) - .map_err(|err| IOError::from_zip(err))?; + .map_err(IOError::from_zip)?; if let Some(file) = archive.file_names().next() { if let Some(dir) = file.split('/').next() { @@ -81,7 +81,7 @@ pub async fn install_java(java_version: u32) -> crate::Result { send_ingress(&ingress, 0.0, Some("extracing java binary")).await?; archive .extract(&path) - .map_err(|err| IOError::from_zip(err))?; + .map_err(IOError::from_zip)?; send_ingress(&ingress, 10.0, Some("extracted java binary")).await?; let mut base_path = path.join( download diff --git a/core/src/api/logger.rs b/core/src/api/logger.rs index 0f6ff39f..7f83e0f7 100644 --- a/core/src/api/logger.rs +++ b/core/src/api/logger.rs @@ -76,7 +76,7 @@ pub async fn get_logs_by_type( let age = entry .metadata()? .created() - .unwrap_or_else(|_| SystemTime::UNIX_EPOCH); + .unwrap_or(SystemTime::UNIX_EPOCH); let path = entry.path(); if !path.is_file() { continue; @@ -84,7 +84,7 @@ pub async fn get_logs_by_type( if let Some(name) = path.file_name() { let name = name.to_string_lossy().to_string(); - logs.push(LogManager::initialize(log_type, age, &cluster_path, name, clear).await); + logs.push(LogManager::initialize(log_type, age, cluster_path, name, clear).await); } } } @@ -144,7 +144,7 @@ pub async fn get_logs_by_file( let metadata = std::fs::metadata(&path)?; let age = metadata .created() - .unwrap_or_else(|_| SystemTime::UNIX_EPOCH); + .unwrap_or(SystemTime::UNIX_EPOCH); LogManager::initialize(log_type, age, &cluster_path, log_file, Some(true)).await } @@ -311,7 +311,7 @@ impl LogOutput { pub fn censor_secrets( mut output: String, credentials: &Vec, - credentials_store: Option, + _credentials_store: Option, ) -> Self { let username = whoami::username(); let realname = whoami::realname(); diff --git a/core/src/api/package/import/mod.rs b/core/src/api/package/import/mod.rs index 83f00942..ba1e07ce 100644 --- a/core/src/api/package/import/mod.rs +++ b/core/src/api/package/import/mod.rs @@ -3,7 +3,7 @@ use crate::prelude::ClusterPath; use crate::proxy::send::{init_or_edit_ingress, send_ingress}; use crate::proxy::IngressId; -use crate::store::Clusters; + use crate::utils::http::{self, IoSemaphore}; use crate::utils::io::{self, IOError}; use serde::{Deserialize, Serialize}; @@ -79,7 +79,7 @@ pub async fn import_instances(import: ImportType, path: PathBuf) -> crate::Resul ImportType::TLauncher => "instances".to_string(), ImportType::Technic => "instances".to_string(), ImportType::FTBLauncher => "instances".to_string(), - _ | ImportType::Unknown => { + _ => { return Err(anyhow::anyhow!("launcher type unknown, cant import").into()) } }; @@ -96,14 +96,12 @@ pub async fn import_instances(import: ImportType, path: PathBuf) -> crate::Resul .map_err(|e| IOError::with_path(e, &instances_dir))? { let path = e.path(); - if path.is_dir() { - if is_valid_instance(path.clone(), import).await { - let name = path.file_name(); - if let Some(name) = name { - instances.push(name.to_string_lossy().to_string()); - } - } - } + if path.is_dir() && is_valid_instance(path.clone(), import).await { + let name = path.file_name(); + if let Some(name) = name { + instances.push(name.to_string_lossy().to_string()); + } + } } Ok(instances) @@ -255,7 +253,7 @@ pub async fn copy_minecraft( io_semaphore: &IoSemaphore, old_ingress: Option, ) -> crate::Result { - let cluster_full = cluster_path.full_path().await?; + let _cluster_full = cluster_path.full_path().await?; let subfiles = sub(&minecraft_path).await?; let total_subfiles = subfiles.len() as u64; let ingress = init_or_edit_ingress( diff --git a/core/src/api/proxy/mod.rs b/core/src/api/proxy/mod.rs index 15791554..200428d0 100644 --- a/core/src/api/proxy/mod.rs +++ b/core/src/api/proxy/mod.rs @@ -52,7 +52,7 @@ impl Drop for IngressId { #[cfg(feature = "tauri")] { - let ingress_feed_uuid = ingress.ingress_uuid; + let _ingress_feed_uuid = ingress.ingress_uuid; let event = ingress.ingress_type.clone(); let fraction = ingress.current / ingress.total; diff --git a/core/src/lib.rs b/core/src/lib.rs index 25014d6a..cde6a305 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -2,7 +2,7 @@ //! //! A library used as a core for our launcher and Rust APIs. -#![warn(unused_import_braces, missing_debug_implementations)] +#![warn(unused_import_braces)] #![deny(unused_must_use)] #[macro_use] diff --git a/core/src/store/clusters.rs b/core/src/store/clusters.rs index ccea989e..64f45a5d 100644 --- a/core/src/store/clusters.rs +++ b/core/src/store/clusters.rs @@ -69,7 +69,7 @@ impl ClusterPath { /// Validate the cluster and clone the current [`ClusterPath`]. pub async fn cluster_path(&self) -> crate::Result { - if let Some(c) = crate::cluster::get(&self, None).await? { + if let Some(c) = crate::cluster::get(self, None).await? { Ok(c.cluster_path()) } else { Err(anyhow::anyhow!( @@ -403,7 +403,7 @@ impl Cluster { /// Handle a cluster crash. pub fn handle_crash(path: ClusterPath) { tokio::task::spawn(async move { - let mut res = async { + let res = async { let cluster = crate::api::cluster::get(&path, None).await?; if let Some(cluster) = cluster { if cluster.stage == ClusterStage::Installed { diff --git a/core/src/store/credentials.rs b/core/src/store/credentials.rs index 312b78b5..abb453a5 100644 --- a/core/src/store/credentials.rs +++ b/core/src/store/credentials.rs @@ -21,17 +21,17 @@ impl Credentials { pub fn new>( path: P, password: Zeroizing>, - dirs: &Directories, - io_semaphore: &IoSemaphore, + _dirs: &Directories, + _io_semaphore: &IoSemaphore, ) -> crate::Result { let path = SnapshotPath::from_path(path); let stronghold = iota_stronghold::Stronghold::default(); let keyprovider = - KeyProvider::try_from(password).map_err(|e| StrongholdError::MemoryError(e))?; + KeyProvider::try_from(password).map_err(StrongholdError::MemoryError)?; if path.exists() { stronghold .load_snapshot(&keyprovider, &path) - .map_err(|e| StrongholdError::ClientError(e))?; + .map_err(StrongholdError::ClientError)?; } Ok(Self { inner: stronghold, @@ -43,7 +43,7 @@ impl Credentials { pub fn save(&self) -> crate::Result<()> { self.inner .commit_with_keyprovider(&self.path, &self.keyprovider) - .map_err(|e| StrongholdError::ClientError(e))?; + .map_err(StrongholdError::ClientError)?; Ok(()) } diff --git a/core/src/store/dirs.rs b/core/src/store/dirs.rs index 671ebb5e..79ea023c 100644 --- a/core/src/store/dirs.rs +++ b/core/src/store/dirs.rs @@ -43,7 +43,7 @@ impl Directories { /// Initialize the core directory manager #[tracing::instrument] pub fn initalize(settings: &Settings) -> crate::Result { - let cwd = std::env::current_dir().map_err(|err| DirectoryError::WorkingDir(err))?; + let cwd = std::env::current_dir().map_err(DirectoryError::WorkingDir)?; let settings_dir = Self::init_settings_dir().ok_or(DirectoryError::ConfigDir)?; let config_dir = settings .config_dir diff --git a/core/src/store/minecraft.rs b/core/src/store/minecraft.rs index afb29315..12386f9f 100644 --- a/core/src/store/minecraft.rs +++ b/core/src/store/minecraft.rs @@ -878,7 +878,6 @@ async fn send_signed_request( current_date: DateTime, ) -> Result, MinecraftAuthError> { let auth = authorization - .clone() .map_or(Vec::new(), |v| v.as_bytes().to_vec()); let body = serde_json::to_vec(&raw_body) .map_err(|source| MinecraftAuthError::SerializeError { step, source })?; diff --git a/core/src/store/package.rs b/core/src/store/package.rs index ec1a7c69..224152de 100644 --- a/core/src/store/package.rs +++ b/core/src/store/package.rs @@ -23,11 +23,11 @@ use super::{Cluster, PackagePath}; // #[tracing::instrument(skip(paths, cluster, io_semaphore, fetch_semaphore))] #[onelauncher_debug::debugger] pub async fn generate_context( - cluster: Cluster, + _cluster: Cluster, paths: Vec, - cache_path: PathBuf, - io_semaphore: &IoSemaphore, - fetch_semaphore: &FetchSemaphore, + _cache_path: PathBuf, + _io_semaphore: &IoSemaphore, + _fetch_semaphore: &FetchSemaphore, // credentials: &Credentials, ) -> crate::Result> { let mut hashes = HashMap::new(); @@ -59,7 +59,7 @@ pub async fn generate_context( hashes.insert(hash, path.clone()); } - let mut result = HashMap::new(); + let result = HashMap::new(); // TODO(pauline): Finish this // let mut stream = tokio_stream::iter(result_packages); // while let Some((k, v)) = stream.next().await { diff --git a/core/src/store/processor.rs b/core/src/store/processor.rs index 4c604723..6ac4243b 100644 --- a/core/src/store/processor.rs +++ b/core/src/store/processor.rs @@ -40,6 +40,12 @@ pub enum IngressProcessType { // Fetch, } +impl Default for IngressProcessor { + fn default() -> Self { + Self::new() + } +} + impl IngressProcessor { /// Initialize a new ingresss process manager. pub fn new() -> Self { diff --git a/core/src/utils/io.rs b/core/src/utils/io.rs index 17873291..bc3914af 100644 --- a/core/src/utils/io.rs +++ b/core/src/utils/io.rs @@ -201,17 +201,17 @@ pub fn extract_archive(archive: &PathBuf, dest: &PathBuf) -> crate::Result<()> { pub fn extract_zip(archive: &PathBuf, dest: &PathBuf) -> Result<(), IOError> { let file = File::open(archive).map_err(|err| IOError::with_path(err, archive.as_path()))?; - let archive = zip::ZipArchive::new(file).map_err(|err| IOError::from_zip(err)); + let archive = zip::ZipArchive::new(file).map_err(IOError::from_zip); archive? .extract(dest) - .map_err(|err| IOError::from_zip(err))?; + .map_err(IOError::from_zip)?; Ok(()) } pub fn extract_tar_gz(archive: &PathBuf, dest: &PathBuf) -> Result<(), IOError> { - let file = File::open(archive).map_err(|err| IOError::from(err))?; + let file = File::open(archive).map_err(IOError::from)?; let tar_gz = flate2::read::GzDecoder::new(file); let mut archive = tar::Archive::new(tar_gz); - archive.unpack(dest).map_err(|err| IOError::from(err))?; + archive.unpack(dest).map_err(IOError::from)?; Ok(()) }