Add Cleanup
struct to run all hooks
This commit is contained in:
parent
641eff3378
commit
bd5090069d
34
src/cleanup/mod.rs
Normal file
34
src/cleanup/mod.rs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
use {
|
||||||
|
super::Hooks,
|
||||||
|
crate::{InstallError, InstallMessage},
|
||||||
|
rayon::prelude::{IntoParallelRefIterator, ParallelIterator},
|
||||||
|
std::{error::Error, sync::mpsc::Sender},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Cleanup {
|
||||||
|
hooks: Vec<Hooks>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Cleanup {
|
||||||
|
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(())
|
||||||
|
}
|
||||||
|
}
|
@ -23,12 +23,14 @@ 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,
|
||||||
@ -46,9 +48,15 @@ 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(String),
|
PostInstallStdout(Vec<u8>),
|
||||||
/// The output of the post install script sent to stderr
|
/// The output of the post install script sent to stderr
|
||||||
PostInstallStderr(String),
|
PostInstallStderr(Vec<u8>),
|
||||||
|
/// 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
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#![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;
|
||||||
@ -14,6 +15,7 @@ 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},
|
||||||
|
Loading…
Reference in New Issue
Block a user