Compare commits

..

No commits in common. "1d595e0f1efa5b7ddef362d3d75ccf8ee9a87294" and "641eff33786339540b86690c88d9509bc6db3655" have entirely different histories.

4 changed files with 12 additions and 70 deletions

View File

@ -1,51 +0,0 @@
use {
super::Hooks,
crate::{InstallError, InstallMessage},
rayon::prelude::{IntoParallelRefIterator, ParallelIterator},
std::{error::Error, sync::mpsc::Sender},
};
#[derive(Debug, Default)]
pub struct Cleanup {
hooks: Vec<Hooks>,
}
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>> {
self.hooks
.par_iter()
.try_for_each_with(sender, |sender, hook| {
let output = hook.run()?;
match hook {
Hooks::Man => sender.send(InstallMessage::Man)?,
Hooks::Info(s) => sender.send(InstallMessage::Info(s.clone()))?,
Hooks::GlibSchema => sender.send(InstallMessage::GlibSchemas)?,
Hooks::User(u, _) => sender.send(InstallMessage::UserCreated(u.clone()))?,
Hooks::Group(g, _) => sender.send(InstallMessage::GroupCreated(g.clone()))?,
Hooks::Pinstall(_) => {
sender.send(InstallMessage::PostInstallStdout(output.stdout))?;
sender.send(InstallMessage::PostInstallStderr(output.stderr))?;
}
}
Ok::<(), InstallError>(())
})?;
Ok(())
}
}

View File

@ -5,7 +5,7 @@ mod cli;
use { use {
clap::ArgMatches, clap::ArgMatches,
cli::cli, cli::cli,
hpk::{Cleanup, CreationError, Creator, Dependency, InstallMessage, Installer, Message, Specs, Version}, hpk::{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 = Cleanup::new(); let mut hooks = vec![];
installer.install(&mut hooks, sender)?; installer.install(&mut hooks, sender)?;
match handle.join() { match handle.join() {
Ok(package) => { Ok(package) => {

View File

@ -3,7 +3,6 @@ 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,
}, },
@ -24,14 +23,12 @@ use {
zstd::Decoder, zstd::Decoder,
}; };
#[derive(Debug)]
/// Represents a symbolic link /// Represents a symbolic link
pub struct Link { pub struct Link {
pub path: PathBuf, pub path: PathBuf,
pub target: PathBuf, pub target: PathBuf,
} }
#[derive(Debug)]
/// Messages sent from and `Installer` to the calling thread /// Messages sent from and `Installer` to the calling thread
pub enum InstallMessage { pub enum InstallMessage {
ArchiveRead, ArchiveRead,
@ -49,15 +46,9 @@ pub enum InstallMessage {
/// A `Group` has been successfully created /// A `Group` has been successfully created
GroupCreated(Group), GroupCreated(Group),
/// The output of the post install script sent to stdout /// The output of the post install script sent to stdout
PostInstallStdout(Vec<u8>), PostInstallStdout(String),
/// The output of the post install script sent to stderr /// The output of the post install script sent to stderr
PostInstallStderr(Vec<u8>), PostInstallStderr(String),
/// Update the mandoc db
Man,
/// Update the info db
Info(String),
/// Glib schemas updated
GlibSchemas,
} }
/// Installs a package into it's specified rootfs /// Installs a package into it's specified rootfs
@ -87,7 +78,7 @@ impl<T: io::Read> Installer<T> {
pub fn install( pub fn install(
self, self,
hooks: &mut Cleanup, hooks: &mut Vec<Hooks>,
sender: Sender<InstallMessage>, sender: Sender<InstallMessage>,
) -> Result<Package, Error> { ) -> Result<Package, Error> {
let reader = Decoder::new(self.reader)?; let reader = Decoder::new(self.reader)?;
@ -137,7 +128,9 @@ 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()
@ -145,9 +138,11 @@ 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
let entry = package let entry = package
.plist .plist
@ -239,7 +234,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 Cleanup, hooks: &mut Vec<Hooks>,
pkgname: &str, pkgname: &str,
root: &Path, root: &Path,
) -> Result<(), Error> { ) -> Result<(), Error> {

View File

@ -1,6 +1,5 @@
#![warn(clippy::all, clippy::pedantic)] #![warn(clippy::all, clippy::pedantic)]
#![allow(clippy::must_use_candidate, clippy::missing_errors_doc)] #![allow(clippy::must_use_candidate, clippy::missing_errors_doc)]
mod cleanup;
mod creator; mod creator;
mod db; mod db;
mod hooks; mod hooks;
@ -15,7 +14,6 @@ mod version;
use std::path::PathBuf; use std::path::PathBuf;
pub use { pub use {
cleanup::Cleanup,
creator::{CreationError, Creator, Message}, creator::{CreationError, Creator, Message},
db::Database, db::Database,
hooks::{Hooks, Pinstall}, hooks::{Hooks, Pinstall},