🔨 chore(core): apply cargo clippy fixes

This commit is contained in:
Pauline 2024-05-11 06:31:44 +02:00
parent e5a0bc6026
commit 1a71848be0
No known key found for this signature in database
GPG key ID: 722BB181973296AE
13 changed files with 48 additions and 49 deletions

View file

@ -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;

View file

@ -67,7 +67,7 @@ pub async fn install_java(java_version: u32) -> crate::Result<PathBuf> {
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<PathBuf> {
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

View file

@ -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<MinecraftCredentials>,
credentials_store: Option<Credentials>,
_credentials_store: Option<Credentials>,
) -> Self {
let username = whoami::username();
let realname = whoami::realname();

View file

@ -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<IngressId>,
) -> crate::Result<IngressId> {
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(

View file

@ -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;

View file

@ -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]

View file

@ -69,7 +69,7 @@ impl ClusterPath {
/// Validate the cluster and clone the current [`ClusterPath`].
pub async fn cluster_path(&self) -> crate::Result<ClusterPath> {
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 {

View file

@ -21,17 +21,17 @@ impl Credentials {
pub fn new<P: AsRef<Path>>(
path: P,
password: Zeroizing<Vec<u8>>,
dirs: &Directories,
io_semaphore: &IoSemaphore,
_dirs: &Directories,
_io_semaphore: &IoSemaphore,
) -> crate::Result<Self> {
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(())
}

View file

@ -43,7 +43,7 @@ impl Directories {
/// Initialize the core directory manager
#[tracing::instrument]
pub fn initalize(settings: &Settings) -> crate::Result<Self> {
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

View file

@ -878,7 +878,6 @@ async fn send_signed_request<T: serde::de::DeserializeOwned>(
current_date: DateTime<Utc>,
) -> Result<SignedRequestResponse<T>, 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 })?;

View file

@ -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<PathBuf>,
cache_path: PathBuf,
io_semaphore: &IoSemaphore,
fetch_semaphore: &FetchSemaphore,
_cache_path: PathBuf,
_io_semaphore: &IoSemaphore,
_fetch_semaphore: &FetchSemaphore,
// credentials: &Credentials,
) -> crate::Result<HashMap<PackagePath, Package>> {
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 {

View file

@ -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 {

View file

@ -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(())
}