diff --git a/pkgr/Cargo.toml b/pkgr/Cargo.toml index d6b098f..cb52813 100644 --- a/pkgr/Cargo.toml +++ b/pkgr/Cargo.toml @@ -25,3 +25,4 @@ reqwest = { version = "0.11.18", features = ["blocking"] } tar = "0.4.39" humantime = "2.1.0" expanduser = "1.2.2" +url = { version = "2.4.0", features = ["serde"] } \ No newline at end of file diff --git a/pkgr/skel/etc/pkgr.d/repos.toml b/pkgr/skel/etc/pkgr.d/repos.toml new file mode 100644 index 0000000..cf1316a --- /dev/null +++ b/pkgr/skel/etc/pkgr.d/repos.toml @@ -0,0 +1,3 @@ +[repo.main] +name = "Main" +url = "tcp://pkgs.ixvd.net:1050" \ No newline at end of file diff --git a/pkgr/skel/etc/pkgr.toml b/pkgr/skel/etc/pkgr.toml new file mode 100644 index 0000000..41f8e2c --- /dev/null +++ b/pkgr/skel/etc/pkgr.toml @@ -0,0 +1,6 @@ +build_by_default = false +tmp_dir = "/tmp/pkgr" + +[storage] +repo_file = "/etc/pkgr.d/repos.toml" +data_dir = "/var/lib/pkgr/packages" \ No newline at end of file diff --git a/pkgr/src/config.rs b/pkgr/src/config/mod.rs similarity index 78% rename from pkgr/src/config.rs rename to pkgr/src/config/mod.rs index 9a932d2..4c6876e 100644 --- a/pkgr/src/config.rs +++ b/pkgr/src/config/mod.rs @@ -1,4 +1,8 @@ use serde::{Deserialize, Serialize}; +use storage::Storage; + +mod storage; +pub mod repos; #[derive(Debug, Serialize, Deserialize)] pub struct Config { @@ -6,13 +10,16 @@ pub struct Config { pub build_by_default: bool, #[serde(default)] pub tmp_dir: Option, + #[serde(default)] + pub storage: Storage } impl Default for Config { fn default() -> Config { Config { build_by_default: false, - tmp_dir: Some(String::from("/tmp/pkgr")) + tmp_dir: Some(String::from("/tmp/pkgr")), + storage: Storage::default() } } } diff --git a/pkgr/src/config/repos.rs b/pkgr/src/config/repos.rs new file mode 100644 index 0000000..d689a92 --- /dev/null +++ b/pkgr/src/config/repos.rs @@ -0,0 +1,25 @@ +use std::collections::HashMap; +use std::str::FromStr; +use serde::{Deserialize, Serialize}; +use url::Url; + +#[derive(Clone, Serialize, Deserialize)] +pub struct Repo { + #[serde(default)] + pub name: String, + pub uri: Url +} + +impl Default for Repo { + fn default() -> Self { + Repo { + name: String::from("Repo"), + uri: Url::parse("tcp://0.0.0.0:0000").unwrap() + } + } +} + +#[derive(Clone, Serialize, Deserialize)] +pub struct RepoFile { + pub repos: HashMap +} \ No newline at end of file diff --git a/pkgr/src/config/storage.rs b/pkgr/src/config/storage.rs new file mode 100644 index 0000000..ba18e5f --- /dev/null +++ b/pkgr/src/config/storage.rs @@ -0,0 +1,20 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize)] +pub struct Storage { + /// Where the repositories are defined. + #[serde(default)] + pub repo_file: String, + /// Where to store pkgs data + #[serde(default)] + pub data_dir: String +} + +impl Default for Storage { + fn default() -> Self { + Storage { + repo_file: String::from("/etc/pkgr.d/repos.toml"), + data_dir: String::from("/var/lib/pkgr/packages"), + } + } +} diff --git a/pkgr/src/package/installer/mod.rs b/pkgr/src/package/installer/mod.rs index 30343cb..4dbeab0 100644 --- a/pkgr/src/package/installer/mod.rs +++ b/pkgr/src/package/installer/mod.rs @@ -7,6 +7,7 @@ use log::{debug, trace}; use errors::{BinError, BuildError, InstallError}; use manifest::Manifest; use pkgfile::PKGFile; +use crate::CONFIG; use crate::tmpfs::TempDir; use crate::types::fetch::TryFetch; @@ -108,11 +109,17 @@ impl PackageInstaller { } } - match self.install_type { + let r = match self.install_type { InstallType::Bin => self.bin() .map_err(|e| InstallError::BinError(e)), InstallType::Build => self.build() .map_err(|e| InstallError::BuildError(e)), + }; + + if let Err(e) = r { + return Err(e); } + + Ok(()) } }