summaryrefslogblamecommitdiff
path: root/src/cache.rs
blob: c9286708fe7d9698d5e534dcfa201e5e7710e457 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12



                         
 






                                                                   
                                         



















                                                                              
                                                                                 


                                          
use std::{
    collections::HashMap,
    fs::{copy, read_dir},
};

/// .
///
/// # Panics
///
/// Panics if .
pub fn get_cached_versions(path: &str) -> HashMap<String, String> {
    let mut versions: HashMap<String, String> = HashMap::new();
    for file in read_dir(path).unwrap() {
        let path = file.unwrap().path();
        if path.is_file() && path.extension().ok_or("BAH").unwrap() == "jar" {
            let pathstr = path.to_str().ok_or("BAH").unwrap();
            let namesplit: Vec<&str> = pathstr.split('.').collect();
            versions.insert(
                String::from(namesplit[namesplit.len() - 2]),
                String::from(pathstr),
            );
        }
    }
    versions
}

/// .
///
/// # Panics
///
/// Panics if .
pub fn copy_cached_version(version_path: &str, download_path: &str) {
    let versplit: Vec<&str> = version_path.split('/').collect();
    let download = format!("{}/{}", download_path, versplit[versplit.len() - 1]);
    // println!("{:#?}", download);
    copy(version_path, download).unwrap();
}