rework section loading

This commit is contained in:
steven-omaha
2023-01-09 19:06:51 +01:00
parent 4907787911
commit 26c1e317bd
8 changed files with 32 additions and 14 deletions
+13
View File
@@ -20,5 +20,18 @@ macro_rules! impl_backend_constants {
fn get_managed_packages(&self) -> &HashSet<Package> {
&self.packages
}
fn load(&mut self, groups: &HashSet<Group>) {
let own_section_name = self.get_section();
groups
.iter()
.flat_map(|g| &g.sections)
.filter(|section| section.name == own_section_name)
.flat_map(|section| &section.packages)
.for_each(|package| {
self.packages.insert(package.clone());
})
}
};
}
+4 -5
View File
@@ -6,7 +6,7 @@ use std::collections::HashSet;
use std::os::unix::process::CommandExt;
use std::process::Command;
use crate::Package;
use crate::{Group, Package};
pub use pacman::Pacman;
pub use rust::Rust;
@@ -36,6 +36,7 @@ impl Backends {
}
}
#[derive(Debug)]
pub(crate) struct BackendIter(Option<Backends>);
impl Iterator for BackendIter {
@@ -62,6 +63,7 @@ pub(crate) trait Backend {
fn get_switches_install(&self) -> Switches;
fn get_switches_remove(&self) -> Switches;
fn get_managed_packages(&self) -> &HashSet<Package>;
fn load(&mut self, groups: &HashSet<Group>);
/// Get all packages that are installed in the system.
fn get_all_installed_packages(&self) -> HashSet<Package>;
@@ -118,10 +120,7 @@ pub(crate) trait Backend {
fn get_unmanaged_packages_sorted(&self) -> Vec<Package> {
let installed = self.get_explicitly_installed_packages();
let required = self.get_managed_packages();
let mut diff: Vec<_> = dbg!(installed)
.difference(dbg!(required))
.cloned()
.collect();
let mut diff: Vec<_> = installed.difference(required).cloned().collect();
diff.sort_unstable();
diff
}
+1 -1
View File
@@ -4,7 +4,7 @@ use alpm::Alpm;
use alpm::PackageReason::Explicit;
use super::{Backend, Switches, Text};
use crate::{impl_backend_constants, Package};
use crate::{impl_backend_constants, Group, Package};
pub struct Pacman {
pub packages: HashSet<Package>,
+1 -1
View File
@@ -1,7 +1,7 @@
use std::{collections::HashSet, process::Command};
use super::{Backend, Switches, Text};
use crate::{impl_backend_constants, Package};
use crate::{impl_backend_constants, Group, Package};
pub struct Rust {
pub packages: HashSet<Package>,