Add push
method for Cleanup struct, slightly simplifying code in the
installer
This commit is contained in:
parent
bd5090069d
commit
1d595e0f1e
@ -5,12 +5,29 @@ use {
|
|||||||
std::{error::Error, sync::mpsc::Sender},
|
std::{error::Error, sync::mpsc::Sender},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Cleanup {
|
pub struct Cleanup {
|
||||||
hooks: Vec<Hooks>,
|
hooks: Vec<Hooks>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cleanup {
|
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<InstallMessage>) -> Result<(), Box<dyn Error>> {
|
pub fn run(&self, sender: Sender<InstallMessage>) -> Result<(), Box<dyn Error>> {
|
||||||
self.hooks
|
self.hooks
|
||||||
.par_iter()
|
.par_iter()
|
||||||
|
@ -5,7 +5,7 @@ mod cli;
|
|||||||
use {
|
use {
|
||||||
clap::ArgMatches,
|
clap::ArgMatches,
|
||||||
cli::cli,
|
cli::cli,
|
||||||
hpk::{CreationError, Creator, Dependency, InstallMessage, Installer, Message, Specs, Version},
|
hpk::{Cleanup, CreationError, Creator, Dependency, InstallMessage, Installer, Message, Specs, Version},
|
||||||
indicatif::{ProgressBar, ProgressStyle},
|
indicatif::{ProgressBar, ProgressStyle},
|
||||||
ron::ser::{to_writer_pretty, PrettyConfig},
|
ron::ser::{to_writer_pretty, PrettyConfig},
|
||||||
std::{
|
std::{
|
||||||
@ -136,7 +136,7 @@ fn install_local<P: AsRef<OsStr> + fmt::Display>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let mut hooks = vec![];
|
let mut hooks = Cleanup::new();
|
||||||
installer.install(&mut hooks, sender)?;
|
installer.install(&mut hooks, sender)?;
|
||||||
match handle.join() {
|
match handle.join() {
|
||||||
Ok(package) => {
|
Ok(package) => {
|
||||||
|
@ -3,6 +3,7 @@ pub use error::Error;
|
|||||||
|
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
|
Cleanup,
|
||||||
tar::{Archive, Node},
|
tar::{Archive, Node},
|
||||||
Entry, Group, Hooks, Package, Pinstall, User,
|
Entry, Group, Hooks, Package, Pinstall, User,
|
||||||
},
|
},
|
||||||
@ -86,7 +87,7 @@ impl<T: io::Read> Installer<T> {
|
|||||||
|
|
||||||
pub fn install(
|
pub fn install(
|
||||||
self,
|
self,
|
||||||
hooks: &mut Vec<Hooks>,
|
hooks: &mut Cleanup,
|
||||||
sender: Sender<InstallMessage>,
|
sender: Sender<InstallMessage>,
|
||||||
) -> Result<Package, Error> {
|
) -> Result<Package, Error> {
|
||||||
let reader = Decoder::new(self.reader)?;
|
let reader = Decoder::new(self.reader)?;
|
||||||
@ -136,9 +137,7 @@ impl<T: io::Read> Installer<T> {
|
|||||||
if let Some(s) = node.header.prefix() {
|
if let Some(s) = node.header.prefix() {
|
||||||
if s.contains("/share/man/") {
|
if s.contains("/share/man/") {
|
||||||
let mut h = hooks.lock().unwrap();
|
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") {
|
} else if s.contains("/share/info") {
|
||||||
hooks
|
hooks
|
||||||
.lock()
|
.lock()
|
||||||
@ -146,9 +145,7 @@ impl<T: io::Read> Installer<T> {
|
|||||||
.push(Hooks::Info(fpath.to_str().unwrap().to_string()));
|
.push(Hooks::Info(fpath.to_str().unwrap().to_string()));
|
||||||
} else if s.contains("/share/glib-2.0/schemas") {
|
} else if s.contains("/share/glib-2.0/schemas") {
|
||||||
let mut h = hooks.lock().unwrap();
|
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
|
// 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(
|
fn pop_pinstall(
|
||||||
archive: &mut Archive,
|
archive: &mut Archive,
|
||||||
hooks: &mut Vec<Hooks>,
|
hooks: &mut Cleanup,
|
||||||
pkgname: &str,
|
pkgname: &str,
|
||||||
root: &Path,
|
root: &Path,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
Loading…
Reference in New Issue
Block a user