summaryrefslogtreecommitdiff
path: root/src/cache.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-09-04 12:03:13 +0200
committerfxqnlr <[email protected]>2024-09-04 12:03:13 +0200
commit29635b9e3833296b2c908914104ba7165d22d3d5 (patch)
treef89e2807e664327fa26191d6f017512a87ba38e7 /src/cache.rs
parent6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043 (diff)
downloadmodlist-29635b9e3833296b2c908914104ba7165d22d3d5.tar
modlist-29635b9e3833296b2c908914104ba7165d22d3d5.tar.gz
modlist-29635b9e3833296b2c908914104ba7165d22d3d5.zip
remove `# Panics` and fix clippy
Diffstat (limited to 'src/cache.rs')
-rw-r--r--src/cache.rs31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/cache.rs b/src/cache.rs
index ef096f7..6ffeb52 100644
--- a/src/cache.rs
+++ b/src/cache.rs
@@ -3,17 +3,15 @@ use std::{
3 fs::{copy, read_dir}, 3 fs::{copy, read_dir},
4}; 4};
5 5
6/// . 6use crate::error::{EType, MLErr, MLE};
7/// 7
8/// # Panics 8/// # Errors
9/// 9pub fn get_cached_versions(path: &str) -> MLE<HashMap<String, String>> {
10/// Panics if .
11#[must_use] pub fn get_cached_versions(path: &str) -> HashMap<String, String> {
12 let mut versions: HashMap<String, String> = HashMap::new(); 10 let mut versions: HashMap<String, String> = HashMap::new();
13 for file in read_dir(path).unwrap() { 11 for file in read_dir(path).map_err(|_| MLErr::new(EType::IoError, "readdir"))? {
14 let path = file.unwrap().path(); 12 let path = file.map_err(|_| MLErr::new(EType::IoError, "file"))?.path();
15 if path.is_file() && path.extension().ok_or("BAH").unwrap() == "jar" { 13 if path.is_file() && path.extension().ok_or(MLErr::new(EType::IoError, "ext"))? == "jar" {
16 let pathstr = path.to_str().ok_or("BAH").unwrap(); 14 let pathstr = path.to_str().ok_or(MLErr::new(EType::IoError, "path"))?;
17 let namesplit: Vec<&str> = pathstr.split('.').collect(); 15 let namesplit: Vec<&str> = pathstr.split('.').collect();
18 versions.insert( 16 versions.insert(
19 String::from(namesplit[namesplit.len() - 2]), 17 String::from(namesplit[namesplit.len() - 2]),
@@ -21,17 +19,14 @@ use std::{
21 ); 19 );
22 } 20 }
23 } 21 }
24 versions 22 Ok(versions)
25} 23}
26 24
27/// . 25/// # Errors
28/// 26pub fn copy_cached_version(version_path: &str, download_path: &str) -> MLE<()> {
29/// # Panics
30///
31/// Panics if .
32pub fn copy_cached_version(version_path: &str, download_path: &str) {
33 let versplit: Vec<&str> = version_path.split('/').collect(); 27 let versplit: Vec<&str> = version_path.split('/').collect();
34 let download = 28 let download =
35 format!("{}/{}", download_path, versplit[versplit.len() - 1]); 29 format!("{}/{}", download_path, versplit[versplit.len() - 1]);
36 copy(version_path, download).unwrap(); 30 copy(version_path, download).map_err(|err| MLErr::new(EType::IoError, &err.to_string()))?;
31 Ok(())
37} 32}