diff options
author | fxqnlr <[email protected]> | 2024-09-04 12:03:13 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-09-04 12:03:13 +0200 |
commit | 29635b9e3833296b2c908914104ba7165d22d3d5 (patch) | |
tree | f89e2807e664327fa26191d6f017512a87ba38e7 /src/files.rs | |
parent | 6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043 (diff) | |
download | modlist-29635b9e3833296b2c908914104ba7165d22d3d5.tar modlist-29635b9e3833296b2c908914104ba7165d22d3d5.tar.gz modlist-29635b9e3833296b2c908914104ba7165d22d3d5.zip |
remove `# Panics` and fix clippy
Diffstat (limited to 'src/files.rs')
-rw-r--r-- | src/files.rs | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/src/files.rs b/src/files.rs index 59f9ed1..636c934 100644 --- a/src/files.rs +++ b/src/files.rs | |||
@@ -19,7 +19,6 @@ use crate::{ | |||
19 | }; | 19 | }; |
20 | 20 | ||
21 | /// # Errors | 21 | /// # Errors |
22 | /// # Panics | ||
23 | pub async fn download_versions( | 22 | pub async fn download_versions( |
24 | list: List, | 23 | list: List, |
25 | config: Cfg, | 24 | config: Cfg, |
@@ -27,19 +26,19 @@ pub async fn download_versions( | |||
27 | progress: &MultiProgress, | 26 | progress: &MultiProgress, |
28 | progress_before: &ProgressBar, | 27 | progress_before: &ProgressBar, |
29 | ) -> MLE<()> { | 28 | ) -> MLE<()> { |
30 | let cached = get_cached_versions(&config.cache); | 29 | let cached = get_cached_versions(&config.cache)?; |
31 | 30 | ||
32 | let mut js = JoinSet::new(); | 31 | let mut js = JoinSet::new(); |
33 | 32 | ||
34 | let style_spinner = ProgressStyle::with_template(STYLE_SPINNER).unwrap(); | 33 | let style_spinner = ProgressStyle::with_template(STYLE_SPINNER).map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?; |
35 | 34 | ||
36 | let all = progress.insert_before( | 35 | let all = progress.insert_before( |
37 | progress_before, | 36 | progress_before, |
38 | ProgressBar::new(versions.len().try_into().unwrap()), | 37 | ProgressBar::new(versions.len().try_into().map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?), |
39 | ); | 38 | ); |
40 | all.set_style( | 39 | all.set_style( |
41 | ProgressStyle::with_template(STYLE_BAR_POS) | 40 | ProgressStyle::with_template(STYLE_BAR_POS) |
42 | .unwrap() | 41 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? |
43 | .progress_chars(PROGRESS_CHARS), | 42 | .progress_chars(PROGRESS_CHARS), |
44 | ); | 43 | ); |
45 | all.set_message(format!("✓Downloading {}", list.id)); | 44 | all.set_message(format!("✓Downloading {}", list.id)); |
@@ -66,7 +65,6 @@ pub async fn download_versions( | |||
66 | } | 65 | } |
67 | 66 | ||
68 | /// # Errors | 67 | /// # Errors |
69 | /// # Panics | ||
70 | async fn download_version( | 68 | async fn download_version( |
71 | config: Cfg, | 69 | config: Cfg, |
72 | list: List, | 70 | list: List, |
@@ -86,7 +84,7 @@ async fn download_version( | |||
86 | if c.is_some() { | 84 | if c.is_some() { |
87 | progress.set_message(format!("Get {} from cache", version.id)); | 85 | progress.set_message(format!("Get {} from cache", version.id)); |
88 | cache_msg = " (cached)"; | 86 | cache_msg = " (cached)"; |
89 | copy_cached_version(&c.unwrap(), &dl_path); | 87 | copy_cached_version(&c.unwrap(), &dl_path)?; |
90 | } else { | 88 | } else { |
91 | let files = version.files; | 89 | let files = version.files; |
92 | let file = match files.clone().into_iter().find(|f| f.primary) { | 90 | let file = match files.clone().into_iter().find(|f| f.primary) { |
@@ -124,7 +122,6 @@ async fn download_version( | |||
124 | } | 122 | } |
125 | 123 | ||
126 | /// # Errors | 124 | /// # Errors |
127 | /// # Panics | ||
128 | async fn download_file( | 125 | async fn download_file( |
129 | url: &str, | 126 | url: &str, |
130 | path: &str, | 127 | path: &str, |
@@ -166,7 +163,6 @@ async fn download_file( | |||
166 | } | 163 | } |
167 | 164 | ||
168 | /// # Errors | 165 | /// # Errors |
169 | /// # Panics | ||
170 | pub fn disable_version( | 166 | pub fn disable_version( |
171 | config: &Cfg, | 167 | config: &Cfg, |
172 | current_list: &List, | 168 | current_list: &List, |
@@ -184,7 +180,6 @@ pub fn disable_version( | |||
184 | } | 180 | } |
185 | 181 | ||
186 | /// # Errors | 182 | /// # Errors |
187 | /// # Panics | ||
188 | pub fn delete_version(list: &List, version: &str) -> MLE<()> { | 183 | pub fn delete_version(list: &List, version: &str) -> MLE<()> { |
189 | let file = get_file_path(list, version)?; | 184 | let file = get_file_path(list, version)?; |
190 | 185 | ||
@@ -194,7 +189,6 @@ pub fn delete_version(list: &List, version: &str) -> MLE<()> { | |||
194 | } | 189 | } |
195 | 190 | ||
196 | /// # Errors | 191 | /// # Errors |
197 | /// # Panics | ||
198 | pub fn get_file_path(list: &List, versionid: &str) -> MLE<String> { | 192 | pub fn get_file_path(list: &List, versionid: &str) -> MLE<String> { |
199 | let mut names: HashMap<String, String> = HashMap::new(); | 193 | let mut names: HashMap<String, String> = HashMap::new(); |
200 | for file in read_dir(&list.download_folder)? { | 194 | for file in read_dir(&list.download_folder)? { |
@@ -220,7 +214,6 @@ pub fn get_file_path(list: &List, versionid: &str) -> MLE<String> { | |||
220 | } | 214 | } |
221 | 215 | ||
222 | /// # Errors | 216 | /// # Errors |
223 | /// # Panics | ||
224 | pub fn get_downloaded_versions(list: &List) -> MLE<HashMap<String, String>> { | 217 | pub fn get_downloaded_versions(list: &List) -> MLE<HashMap<String, String>> { |
225 | let mut versions: HashMap<String, String> = HashMap::new(); | 218 | let mut versions: HashMap<String, String> = HashMap::new(); |
226 | for file in read_dir(&list.download_folder)? { | 219 | for file in read_dir(&list.download_folder)? { |
@@ -243,7 +236,6 @@ pub fn get_downloaded_versions(list: &List) -> MLE<HashMap<String, String>> { | |||
243 | } | 236 | } |
244 | 237 | ||
245 | /// # Errors | 238 | /// # Errors |
246 | /// # Panics | ||
247 | pub fn clean_list_dir(list: &List) -> MLE<()> { | 239 | pub fn clean_list_dir(list: &List) -> MLE<()> { |
248 | let dl_path = &list.download_folder; | 240 | let dl_path = &list.download_folder; |
249 | for entry in std::fs::read_dir(dl_path)? { | 241 | for entry in std::fs::read_dir(dl_path)? { |