summaryrefslogtreecommitdiff
path: root/src/cache.rs
diff options
context:
space:
mode:
authorfx <[email protected]>2023-04-27 10:10:03 +0200
committerfx <[email protected]>2023-04-27 10:10:03 +0200
commit43ca5fec20933fc31dfe7d7dbd1f1b9258612219 (patch)
treeeef58fecfadad90386b38af581abab8cc3d3cfc0 /src/cache.rs
parent4300ad2eb05dddfa4274e04b204f2ad28c87da05 (diff)
parent4e6466af1329f7b9e341df2e76ab696d11f80c93 (diff)
downloadmodlist-43ca5fec20933fc31dfe7d7dbd1f1b9258612219.tar
modlist-43ca5fec20933fc31dfe7d7dbd1f1b9258612219.tar.gz
modlist-43ca5fec20933fc31dfe7d7dbd1f1b9258612219.zip
Merge pull request 'cache' (#3) from cache into master
Reviewed-on: http://raspberrypi.fritz.box:7920/fx/modlist/pulls/3
Diffstat (limited to 'src/cache.rs')
-rw-r--r--src/cache.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/cache.rs b/src/cache.rs
new file mode 100644
index 0000000..11645d1
--- /dev/null
+++ b/src/cache.rs
@@ -0,0 +1,37 @@
1use std::{
2 collections::HashMap,
3 fs::{copy, read_dir},
4};
5
6/// .
7///
8/// # Panics
9///
10/// Panics if .
11pub fn get_cached_versions(path: &str) -> HashMap<String, String> {
12 let mut versions: HashMap<String, String> = HashMap::new();
13 for file in read_dir(path).unwrap() {
14 let path = file.unwrap().path();
15 if path.is_file() && path.extension().ok_or("BAH").unwrap() == "jar" {
16 let pathstr = path.to_str().ok_or("BAH").unwrap();
17 let namesplit: Vec<&str> = pathstr.split('.').collect();
18 versions.insert(
19 String::from(namesplit[namesplit.len() - 2]),
20 String::from(pathstr),
21 );
22 }
23 }
24 versions
25}
26
27/// .
28///
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();
34 let download = format!("{}{}", download_path, versplit[versplit.len() - 1]);
35 // println!("{:#?}", download);
36 copy(version_path, download).unwrap();
37}