diff --git a/src/cleanup/mod.rs b/src/cleanup/mod.rs index 1d79b01..f6de2cb 100644 --- a/src/cleanup/mod.rs +++ b/src/cleanup/mod.rs @@ -5,12 +5,29 @@ use { std::{error::Error, sync::mpsc::Sender}, }; -#[derive(Debug)] +#[derive(Debug, Default)] pub struct Cleanup { hooks: Vec, } impl Cleanup { + pub fn new() -> Self { + Self::default() + } + + pub fn push(&mut self, hook: Hooks) { + match hook { + Hooks::Info(_) | Hooks::User(_, _) | Hooks::Group(_, _) | Hooks::Pinstall(_) => { + self.hooks.push(hook) + } + Hooks::Man | Hooks::GlibSchema => { + if !self.hooks.contains(&hook) { + self.hooks.push(hook); + } + } + } + } + pub fn run(&self, sender: Sender) -> Result<(), Box> { self.hooks .par_iter() diff --git a/src/hpk.rs b/src/hpk.rs index 1ff3341..5301c36 100644 --- a/src/hpk.rs +++ b/src/hpk.rs @@ -5,7 +5,7 @@ mod cli; use { clap::ArgMatches, cli::cli, - hpk::{CreationError, Creator, Dependency, InstallMessage, Installer, Message, Specs, Version}, + hpk::{Cleanup, CreationError, Creator, Dependency, InstallMessage, Installer, Message, Specs, Version}, indicatif::{ProgressBar, ProgressStyle}, ron::ser::{to_writer_pretty, PrettyConfig}, std::{ @@ -136,7 +136,7 @@ fn install_local + fmt::Display>( } } }); - let mut hooks = vec![]; + let mut hooks = Cleanup::new(); installer.install(&mut hooks, sender)?; match handle.join() { Ok(package) => { diff --git a/src/installer/mod.rs b/src/installer/mod.rs index e07b91d..b4690d0 100644 --- a/src/installer/mod.rs +++ b/src/installer/mod.rs @@ -3,6 +3,7 @@ pub use error::Error; use { crate::{ + Cleanup, tar::{Archive, Node}, Entry, Group, Hooks, Package, Pinstall, User, }, @@ -86,7 +87,7 @@ impl Installer { pub fn install( self, - hooks: &mut Vec, + hooks: &mut Cleanup, sender: Sender, ) -> Result { let reader = Decoder::new(self.reader)?; @@ -136,9 +137,7 @@ impl Installer { if let Some(s) = node.header.prefix() { if s.contains("/share/man/") { let mut h = hooks.lock().unwrap(); - if !h.contains(&Hooks::Man) { - h.push(Hooks::Man); - } + h.push(Hooks::Man); } else if s.contains("/share/info") { hooks .lock() @@ -146,9 +145,7 @@ impl Installer { .push(Hooks::Info(fpath.to_str().unwrap().to_string())); } else if s.contains("/share/glib-2.0/schemas") { let mut h = hooks.lock().unwrap(); - if !h.contains(&Hooks::GlibSchema) { - h.push(Hooks::GlibSchema); - } + h.push(Hooks::GlibSchema); } } // Match up a package entry with a tar node @@ -242,7 +239,7 @@ fn pop_appstream(archive: &mut Archive, db_pkgdir: &Path) -> Result<(), Error> { fn pop_pinstall( archive: &mut Archive, - hooks: &mut Vec, + hooks: &mut Cleanup, pkgname: &str, root: &Path, ) -> Result<(), Error> {