From 6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 11:12:04 +0200 Subject: do nearly anything to shut clippy up --- src/files.rs | 66 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 27 deletions(-) (limited to 'src/files.rs') diff --git a/src/files.rs b/src/files.rs index bf5a0a0..59f9ed1 100644 --- a/src/files.rs +++ b/src/files.rs @@ -13,11 +13,13 @@ use crate::{ cache::{copy_cached_version, get_cached_versions}, config::Cfg, db::{mods_get_info, userlist_add_disabled_versions}, - error::{ErrorType, MLError, MLE}, + error::{EType, MLErr, MLE}, modrinth::Version, List, PROGRESS_CHARS, STYLE_BAR_BYTE, STYLE_BAR_POS, STYLE_SPINNER, }; +/// # Errors +/// # Panics pub async fn download_versions( list: List, config: Cfg, @@ -63,6 +65,8 @@ pub async fn download_versions( Ok(()) } +/// # Errors +/// # Panics async fn download_version( config: Cfg, list: List, @@ -90,11 +94,8 @@ async fn download_version( None => files[0].clone(), }; let mut splitname: Vec<&str> = file.filename.split('.').collect(); - let extension = match splitname.pop().ok_or("") { - Ok(e) => e, - Err(..) => { - return Err(MLError::new(ErrorType::Other, "NO_FILE_EXTENSION")) - } + let Ok(extension) = splitname.pop().ok_or("") else { + return Err(MLErr::new(EType::Other, "NO_FILE_EXTENSION")) }; let filename = format!( "{}.mr.{}.{}.{}", @@ -122,6 +123,8 @@ async fn download_version( Ok(()) } +/// # Errors +/// # Panics async fn download_file( url: &str, path: &str, @@ -162,23 +165,27 @@ async fn download_file( Ok(()) } +/// # Errors +/// # Panics pub fn disable_version( config: &Cfg, - current_list: List, + current_list: &List, versionid: String, mod_id: String, ) -> MLE<()> { - let file = get_file_path(¤t_list, String::from(&versionid))?; + let file = get_file_path(current_list, &versionid)?; let disabled = format!("{file}.disabled"); rename(file, disabled)?; - userlist_add_disabled_versions(config, current_list.id, versionid, mod_id)?; + userlist_add_disabled_versions(config, ¤t_list.id, versionid, mod_id)?; Ok(()) } -pub fn delete_version(list: &List, version: String) -> MLE<()> { +/// # Errors +/// # Panics +pub fn delete_version(list: &List, version: &str) -> MLE<()> { let file = get_file_path(list, version)?; remove_file(file)?; @@ -186,16 +193,15 @@ pub fn delete_version(list: &List, version: String) -> MLE<()> { Ok(()) } -pub fn get_file_path(list: &List, versionid: String) -> MLE { +/// # Errors +/// # Panics +pub fn get_file_path(list: &List, versionid: &str) -> MLE { let mut names: HashMap = HashMap::new(); for file in read_dir(&list.download_folder)? { let path = file?.path(); if path.is_file() { - let pathstr = match path.to_str().ok_or("") { - Ok(s) => s, - Err(..) => { - return Err(MLError::new(ErrorType::Other, "INVALID_PATH")) - } + let Ok(pathstr) = path.to_str().ok_or("") else { + return Err(MLErr::new(EType::Other, "INVALID_PATH")) }; let namesplit: Vec<&str> = pathstr.split('.').collect(); let ver_id = namesplit[namesplit.len() - 2]; @@ -203,25 +209,29 @@ pub fn get_file_path(list: &List, versionid: String) -> MLE { } } - let filename = match names.get(&versionid).ok_or("") { - Ok(n) => n, - Err(..) => { - return Err(MLError::new( - ErrorType::ArgumentError, - "VERSION_NOT_FOUND_IN_FILES", - )) - } + let Ok(filename) = names.get(versionid).ok_or("") else { + return Err(MLErr::new( + EType::ArgumentError, + "VERSION_NOT_FOUND_IN_FILES", + )) }; Ok(filename.to_owned()) } -pub fn get_downloaded_versions(list: List) -> MLE> { +/// # Errors +/// # Panics +pub fn get_downloaded_versions(list: &List) -> MLE> { let mut versions: HashMap = HashMap::new(); for file in read_dir(&list.download_folder)? { let path = file?.path(); - if path.is_file() && path.extension().ok_or("BAH").unwrap() == "jar" { - let pathstr = path.to_str().ok_or("BAH").unwrap(); + if path.is_file() + && path + .extension() + .ok_or(MLErr::new(EType::IoError, "extension"))? + == "jar" + { + let pathstr = path.to_str().ok_or(MLErr::new(EType::IoError, "path_to_str"))?; let namesplit: Vec<&str> = pathstr.split('.').collect(); versions.insert( String::from(namesplit[namesplit.len() - 3]), @@ -232,6 +242,8 @@ pub fn get_downloaded_versions(list: List) -> MLE> { Ok(versions) } +/// # Errors +/// # Panics pub fn clean_list_dir(list: &List) -> MLE<()> { let dl_path = &list.download_folder; for entry in std::fs::read_dir(dl_path)? { -- cgit v1.2.3