add more code

This commit is contained in:
steven-omaha
2022-09-02 19:42:01 +02:00
parent c51aa6060a
commit ac3ee300d7
10 changed files with 759 additions and 61 deletions
+35
View File
@@ -0,0 +1,35 @@
use crate::Package;
use alpm::Alpm;
use alpm::PackageReason::Explicit;
use std::collections::HashSet;
pub fn get_all_installed_packages() -> HashSet<Package> {
convert_to_pacdef_packages(get_all_installed_packages_alpm())
}
fn get_all_installed_packages_alpm() -> HashSet<String> {
let db = Alpm::new("/", "/var/lib/pacman").unwrap();
db.localdb()
.pkgs()
.iter()
.map(|p| p.name().to_string())
.collect()
}
pub fn get_explicitly_installed_packages() -> HashSet<Package> {
convert_to_pacdef_packages(get_explicitly_installed_packages_alpm())
}
fn get_explicitly_installed_packages_alpm() -> HashSet<String> {
let db = Alpm::new("/", "/var/lib/pacman").unwrap();
db.localdb()
.pkgs()
.iter()
.filter(|p| p.reason() == Explicit)
.map(|p| p.name().to_string())
.collect()
}
fn convert_to_pacdef_packages(packages: HashSet<String>) -> HashSet<Package> {
packages.into_iter().map(Package::from).collect()
}