diff options
author | fxqnlr <[email protected]> | 2024-09-04 17:32:19 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-09-04 17:32:19 +0200 |
commit | ecc4743fdec43eb578e9c35bb008c68909f1517e (patch) | |
tree | 73916114bc2bff8c72f759f5aae11a95d4dede22 /src/cache.rs | |
parent | 11e64fc7560de3cd0def718edf68c31e3dc8be72 (diff) | |
download | modlist-refactor.tar modlist-refactor.tar.gz modlist-refactor.zip |
better error handlingrefactor
Diffstat (limited to 'src/cache.rs')
-rw-r--r-- | src/cache.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/cache.rs b/src/cache.rs index 6ffeb52..199a440 100644 --- a/src/cache.rs +++ b/src/cache.rs | |||
@@ -3,15 +3,15 @@ use std::{ | |||
3 | fs::{copy, read_dir}, | 3 | fs::{copy, read_dir}, |
4 | }; | 4 | }; |
5 | 5 | ||
6 | use crate::error::{EType, MLErr, MLE}; | 6 | use crate::errors::{ConversionError, Error, MLE}; |
7 | 7 | ||
8 | /// # Errors | 8 | /// # Errors |
9 | pub fn get_cached_versions(path: &str) -> MLE<HashMap<String, String>> { | 9 | pub fn get_cached_versions(path: &str) -> MLE<HashMap<String, String>> { |
10 | let mut versions: HashMap<String, String> = HashMap::new(); | 10 | let mut versions: HashMap<String, String> = HashMap::new(); |
11 | for file in read_dir(path).map_err(|_| MLErr::new(EType::IoError, "readdir"))? { | 11 | for file in read_dir(path)? { |
12 | let path = file.map_err(|_| MLErr::new(EType::IoError, "file"))?.path(); | 12 | let path = file?.path(); |
13 | if path.is_file() && path.extension().ok_or(MLErr::new(EType::IoError, "ext"))? == "jar" { | 13 | if path.is_file() && path.extension().ok_or(Error::NoFileExtension)? == "jar" { |
14 | let pathstr = path.to_str().ok_or(MLErr::new(EType::IoError, "path"))?; | 14 | let pathstr = path.to_str().ok_or(ConversionError::InvalidPath)?; |
15 | let namesplit: Vec<&str> = pathstr.split('.').collect(); | 15 | let namesplit: Vec<&str> = pathstr.split('.').collect(); |
16 | versions.insert( | 16 | versions.insert( |
17 | String::from(namesplit[namesplit.len() - 2]), | 17 | String::from(namesplit[namesplit.len() - 2]), |
@@ -27,6 +27,6 @@ pub fn copy_cached_version(version_path: &str, download_path: &str) -> MLE<()> { | |||
27 | let versplit: Vec<&str> = version_path.split('/').collect(); | 27 | let versplit: Vec<&str> = version_path.split('/').collect(); |
28 | let download = | 28 | let download = |
29 | format!("{}/{}", download_path, versplit[versplit.len() - 1]); | 29 | format!("{}/{}", download_path, versplit[versplit.len() - 1]); |
30 | copy(version_path, download).map_err(|err| MLErr::new(EType::IoError, &err.to_string()))?; | 30 | copy(version_path, download)?; |
31 | Ok(()) | 31 | Ok(()) |
32 | } | 32 | } |