Merge branch 'odin' of git.hitchhiker-linux.org:jeang3nie/hpk into odin

This commit is contained in:
Nathan Fisher 2023-04-08 10:16:10 -04:00
commit 784069402d
4 changed files with 81 additions and 12 deletions

14
Cargo.lock generated
View File

@ -392,7 +392,7 @@ dependencies = [
[[package]]
name = "hpk-package"
version = "0.1.0"
source = "git+https://git.hitchhiker-linux.org/jeang3nie/hpk-package.git#90b163eb1b7373085d3c5eb93919eb8ecfedb219"
source = "git+https://git.hitchhiker-linux.org/jeang3nie/hpk-package.git#acbdf2d99284b69a48601f3aeb0a56f295872a4c"
dependencies = [
"chrono",
"deku",
@ -475,9 +475,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.140"
version = "0.2.141"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5"
[[package]]
name = "link-cplusplus"
@ -1263,9 +1263,9 @@ dependencies = [
[[package]]
name = "zstd-safe"
version = "6.0.4+zstd.1.5.4"
version = "6.0.5+zstd.1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7afb4b54b8910cf5447638cb54bf4e8a65cbedd783af98b98c62ffe91f185543"
checksum = "d56d9e60b4b1758206c238a10165fbcae3ca37b01744e394c463463f6529d23b"
dependencies = [
"libc",
"zstd-sys",
@ -1273,9 +1273,9 @@ dependencies = [
[[package]]
name = "zstd-sys"
version = "2.0.7+zstd.1.5.4"
version = "2.0.8+zstd.1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5"
checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c"
dependencies = [
"cc",
"libc",

View File

@ -1,5 +1,5 @@
use {
crate::{Package, Repository, Version},
crate::{Arch, Package, Repository, Version},
hpk_package::ron::{self, ser::PrettyConfig},
rayon::prelude::*,
serde::{Deserialize, Serialize},
@ -19,13 +19,14 @@ use {
pub struct Update {
pub name: String,
pub version: Version,
pub arch: Arch,
pub release: u8,
pub url: Url,
}
impl fmt::Display for Update {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}-{}_{}", self.name, self.version, self.release)
write!(f, "{}-{}_{}_{}", self.name, self.version, self.arch, self.release)
}
}
@ -77,6 +78,7 @@ impl Database {
let update = Update {
name: key.to_string(),
version: remote_package.version.clone(),
arch: remote_package.arch,
release: remote_package.release,
url: repo.base_url.clone(),
};
@ -87,6 +89,7 @@ impl Database {
// into our hashmap
let update = Update {
name: key.to_string(),
arch: remote_package.arch,
version: remote_package.version.clone(),
release: remote_package.release,
url: repo.base_url.clone(),
@ -144,11 +147,12 @@ mod test {
let up = Update {
name: "hpk".to_string(),
version: Version::Number(42),
arch: Arch::aarch64,
release: 1,
url: Url::parse("https://hitchhiker-linux.org/pub/packages/").unwrap(),
}
.to_string();
assert_eq!("hpk-42_1".to_string(), up);
assert_eq!("hpk-42_aarch64_1".to_string(), up);
}
#[test]
@ -156,12 +160,13 @@ mod test {
let up = Update {
name: "hpk".to_string(),
version: Version::Number(42),
arch: Arch::aarch64,
release: 1,
url: Url::parse("https://hitchhiker-linux.org/pub/packages/").unwrap(),
};
let full_url = up.full_url().unwrap().to_string();
assert_eq!(
"https://hitchhiker-linux.org/pub/packages/hpk-42_1.tar.zstd".to_string(),
"https://hitchhiker-linux.org/pub/packages/hpk-42_aarch64_1.tar.zstd".to_string(),
full_url
);
}

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 db;
mod hooks;
mod installer;
mod item;
mod repository;
@ -11,7 +12,7 @@ pub use {
creator::{Creator, Message},
db::Database,
hooks::Hooks,
hpk_package::{tar, Dependency, GitRev, Package, Plist, Rapid, SemVer, Specs, Version},
hpk_package::{tar, Arch, Dependency, GitRev, Package, Plist, Rapid, SemVer, Specs, Version},
item::Item,
repository::Repository,
};