Compare commits

...

3 Commits

Author SHA1 Message Date
Nathan Fisher 1a4d202989 Expand InstallerError enum; 2023-04-08 11:45:39 -04:00
Nathan Fisher 784069402d Merge branch 'odin' of git.hitchhiker-linux.org:jeang3nie/hpk into odin 2023-04-08 10:16:10 -04:00
Nathan Fisher ca9c0d7cdb Skip directories when creating a package from directory; Take an
optional directory when creating a package from file list;
2023-04-06 10:41:10 -04:00
2 changed files with 11 additions and 2 deletions

View File

@ -40,6 +40,7 @@ impl Creator {
.into_iter()
.filter(Result::is_ok)
.map(|x| x.unwrap().path().to_path_buf())
.filter(|x| !x.is_dir())
.collect::<Vec<_>>();
env::set_current_dir(d)?;
Ok(Self {
@ -49,10 +50,15 @@ impl Creator {
})
}
pub fn from_list(list: &[&str], specs: Specs) -> Result<Self, io::Error> {
pub fn from_list(list: &[&str], path: Option<&Path>, specs: Specs) -> Result<Self, io::Error> {
let entries = list.iter().map(|x| Path::new(x).to_path_buf()).collect();
let path = if let Some(p) = path {
p.to_path_buf()
} else {
env::current_dir().unwrap_or(Path::new("/").to_path_buf())
};
Ok(Self {
path: env::current_dir().unwrap_or(Path::new("/").to_path_buf()),
path,
entries,
specs,
})

View File

@ -35,10 +35,12 @@ impl<T: io::Read> Installer<T> {
mod error {
use std::{io, fmt, error::Error};
use hpk_package::tar;
#[derive(Debug)]
pub enum InstallError {
IO(io::Error),
Tar(tar::Error),
}
impl fmt::Display for InstallError {
@ -51,6 +53,7 @@ mod error {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::IO(e) => Some(e),
Self::Tar(e) => Some(e),
}
}
}