From 9c1bdc1e8a74d6c258097e7c2aa9f70ebae30390 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sun, 9 Jul 2023 14:07:07 +0200 Subject: [PATCH] Introduce origin config --- src/main.rs | 6 +++++- src/origin.rs | 12 +++++++----- src/origin/config.rs | 7 +++++++ src/origin/git.rs | 10 +++++++--- 4 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 src/origin/config.rs diff --git a/src/main.rs b/src/main.rs index c5b3c3e..6a40329 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,7 +73,11 @@ async fn main() { ) .init(); - let origin_store = domani::origin::git::FSStore::new(config.origin_store_git_dir_path) + let origin_config = domani::origin::Config { + store_dir_path: config.origin_store_git_dir_path, + }; + + let origin_store = domani::origin::git::FSStore::new(&origin_config) .expect("git origin store initialization failed"); let domain_checker = domani::domain::checker::DNSChecker::new( diff --git a/src/origin.rs b/src/origin.rs index 7a98736..f817f18 100644 --- a/src/origin.rs +++ b/src/origin.rs @@ -1,13 +1,15 @@ -use crate::error::unexpected; -use crate::util; -use std::sync; - +mod config; +mod descr; pub mod git; pub mod mux; -mod descr; +pub use config::*; pub use descr::Descr; +use crate::error::unexpected; +use crate::util; +use std::sync; + #[derive(thiserror::Error, Clone, Debug, PartialEq)] pub enum SyncError { #[error("invalid url")] diff --git a/src/origin/config.rs b/src/origin/config.rs new file mode 100644 index 0000000..d1592d0 --- /dev/null +++ b/src/origin/config.rs @@ -0,0 +1,7 @@ +use serde::Deserialize; +use std::path; + +#[derive(Deserialize)] +pub struct Config { + pub store_dir_path: path::PathBuf, +} diff --git a/src/origin/git.rs b/src/origin/git.rs index 79b3fb4..5000dbb 100644 --- a/src/origin/git.rs +++ b/src/origin/git.rs @@ -34,7 +34,8 @@ pub struct FSStore { } impl FSStore { - pub fn new(dir_path: PathBuf) -> io::Result { + pub fn new(config: &origin::Config) -> io::Result { + let dir_path = config.store_dir_path.clone(); fs::create_dir_all(&dir_path)?; Ok(Self { dir_path, @@ -336,13 +337,16 @@ impl super::Store for FSStore { #[cfg(test)] mod tests { - use crate::origin::{self, Store}; + use crate::origin::{self, Config, Store}; use futures::StreamExt; use tempdir::TempDir; #[tokio::test] async fn basic() { let tmp_dir = TempDir::new("origin_store_git").unwrap(); + let config = Config { + store_dir_path: tmp_dir.path().to_path_buf(), + }; let curr_dir = format!("file://{}", std::env::current_dir().unwrap().display()); @@ -356,7 +360,7 @@ mod tests { branch_name: String::from("some_other_branch"), }; - let store = super::FSStore::new(tmp_dir.path().to_path_buf()).expect("store created"); + let store = super::FSStore::new(&config).expect("store created"); store.sync(&descr).expect("sync should succeed"); store.sync(&descr).expect("second sync should succeed");