Create Installer struct

This commit is contained in:
Nathan Fisher 2023-04-07 19:12:28 -04:00
parent a07166375a
commit ab6e7441f1
3 changed files with 65 additions and 1 deletions

2
Cargo.lock generated
View File

@ -392,7 +392,7 @@ dependencies = [
[[package]] [[package]]
name = "hpk-package" name = "hpk-package"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.hitchhiker-linux.org/jeang3nie/hpk-package.git#723d697e9085a575c1f6d59baf1e79819452d747" source = "git+https://git.hitchhiker-linux.org/jeang3nie/hpk-package.git#acbdf2d99284b69a48601f3aeb0a56f295872a4c"
dependencies = [ dependencies = [
"chrono", "chrono",
"deku", "deku",

63
src/installer/mod.rs Normal file
View File

@ -0,0 +1,63 @@
use std::{io, path::{PathBuf, Path}, ffi::OsStr, sync::mpsc::Sender};
pub use error::InstallError;
use hpk_package::{Package, User, Group};
pub struct Link {
pub path: PathBuf,
pub target: PathBuf,
}
pub enum InstallMessage {
FileInstalled(PathBuf),
DirectoryCreated(PathBuf),
LinkCreated(Link),
UserCreated(User),
GroupCreated(Group),
PostInstall(String),
}
pub struct Installer<T: io::Read> {
path: PathBuf,
package: Package,
reader: T,
}
impl<T: io::Read> Installer<T> {
pub fn new<P: AsRef<OsStr>>(path: P, package: Package, reader: T) -> Self {
let path = Path::new(&path).to_path_buf();
Self { path, package, reader }
}
pub fn install(&mut self, sender: Sender<InstallMessage>) -> Result<(), Box<InstallError>> {
unimplemented!();
}
}
mod error {
use std::{io, fmt, error::Error};
#[derive(Debug)]
pub enum InstallError {
IO(io::Error),
}
impl fmt::Display for InstallError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{self:?}")
}
}
impl Error for InstallError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::IO(e) => Some(e),
}
}
}
impl From<io::Error> for InstallError {
fn from(value: io::Error) -> Self {
Self::IO(value)
}
}
}

View File

@ -2,6 +2,7 @@
mod creator; mod creator;
mod db; mod db;
mod hooks; mod hooks;
mod installer;
mod item; mod item;
mod repository; mod repository;