check if installed version is highest version

This commit is contained in:
Lilly Rosaline 2022-02-13 12:52:19 -06:00
parent fed7106c20
commit 979cbacc5a

View file

@ -8,25 +8,31 @@ pub fn find_package_in_repositories(package: &str, installed: Option<u64>) -> Op
let mut hits: Vec<String> = vec!();
let client = reqwest::Client::new();
let repo_file = File::open("/var/gaypack/repositories.list").expect("Failed to open repository list");
let mut candidates: HashMap<u64, String> = HashMap::new();
let mut candidates: HashMap<String, u64> = HashMap::new();
for repository in std::io::BufReader::new(repo_file).lines() {
let repository = repository.expect("Unexpected error"); // i find this line kinda funny for some reason
let resp = block_on(client.get(format!("{}/gaypack/{}/latest/Package.toml", repository, package)).send()).expect("GET request failed");
let status = resp.status();
let text = block_on(resp.text()).expect("Failed to receive packet body");
if installed.is_some() {
candidates.insert(installed.unwrap(), "installed".to_string());
candidates.insert("installed".to_string(), installed.unwrap());
}
let package_data = &crate::package::read_package(text);
dbg!(package_data);
if status == StatusCode::from_u16(200).unwrap() {
candidates.insert(package_data.revision, repository);
candidates.insert(repository, package_data.revision);
}
};
let mut sorted: Vec<_> = candidates.iter().collect();
sorted.sort_by_key(|entry| entry.0);
for (_, repository) in sorted.iter() {
sorted.sort_by_key(|entry| entry.1);
let mut highest_version: u64 = 0;
for (repository, version) in sorted.iter() {
if **version > highest_version {highest_version = **version};
hits.push(repository.as_str().to_string());
}
return Some(hits);
if candidates.get("installed") == Some(highest_version) {
None
} else {
Some(hits)
}
}