From b60c849a735721fab29747011935cca01e2ccf11 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Mon, 22 Jan 2024 16:48:57 +0100 Subject: [PATCH] Remove all_descrs method from origin store --- src/origin.rs | 8 -------- src/origin/git.rs | 31 ------------------------------- src/origin/git_proxy.rs | 10 ---------- src/origin/mux.rs | 16 ++-------------- 4 files changed, 2 insertions(+), 63 deletions(-) diff --git a/src/origin.rs b/src/origin.rs index 075e2dd..e90e6cb 100644 --- a/src/origin.rs +++ b/src/origin.rs @@ -25,12 +25,6 @@ pub enum SyncError { Unexpected(#[from] unexpected::Error), } -#[derive(thiserror::Error, Clone, Debug, PartialEq)] -pub enum AllDescrsError { - #[error(transparent)] - Unexpected(#[from] unexpected::Error), -} - #[derive(thiserror::Error, Debug)] pub enum GetFileError { #[error("descr not synced")] @@ -52,7 +46,5 @@ pub trait Store { /// the origin into the storage. fn sync(&self, descr: &Descr) -> util::BoxFuture<'_, Result<(), SyncError>>; - fn all_descrs(&self) -> Result, AllDescrsError>; - fn get_file(&self, descr: &Descr, path: &str) -> Result; } diff --git a/src/origin/git.rs b/src/origin/git.rs index d088feb..83cf14e 100644 --- a/src/origin/git.rs +++ b/src/origin/git.rs @@ -274,37 +274,6 @@ impl super::Store for FSStore { Box::pin(future::ready(res)) } - fn all_descrs(&self) -> Result, origin::AllDescrsError> { - fs::read_dir(&self.dir_path).or_unexpected()?.map( - |dir_entry_res: io::Result| -> Result { - let descr_id: String = dir_entry_res - .or_unexpected()? - .file_name() - .to_str() - .ok_or_else(|| { - unexpected::Error::from("couldn't convert os string to &str") - })? - .into(); - - let descr_file_path = self.descr_file_path(descr_id.as_ref()); - - // TODO it's possible that opening the file will fail if syncing is - // still ongoing, as writing the descr file is the last step after - // initial sync has succeeded. - let descr_file = fs::File::open(descr_file_path.as_path()) - .map_unexpected_while(|| { - format!("opening descr file {}", descr_file_path.display()) - })?; - - let descr = serde_json::from_reader(descr_file).map_unexpected_while(|| { - format!("reading descr file {}", descr_file_path.display()) - })?; - - Ok(descr) - }, - ).try_collect() - } - fn get_file( &self, descr: &origin::Descr, diff --git a/src/origin/git_proxy.rs b/src/origin/git_proxy.rs index 75a092b..bb64624 100644 --- a/src/origin/git_proxy.rs +++ b/src/origin/git_proxy.rs @@ -168,16 +168,6 @@ impl origin::Store for Proxy { }) } - fn all_descrs(&self) -> Result, origin::AllDescrsError> { - Ok(self - .state - .read() - .unwrap() - .keys() - .map(|d| d.clone()) - .collect()) - } - fn get_file( &self, _descr: &origin::Descr, diff --git a/src/origin/mux.rs b/src/origin/mux.rs index b5ff449..3ae2b53 100644 --- a/src/origin/mux.rs +++ b/src/origin/mux.rs @@ -3,11 +3,9 @@ use crate::{origin, util}; pub struct Store where - S: origin::Store + Sync + Send + 'static, F: Fn(&origin::Descr) -> Option + Sync + Send, { mapping_fn: F, - stores: Vec, } impl Store @@ -15,8 +13,8 @@ where S: origin::Store + Sync + Send + 'static, F: Fn(&origin::Descr) -> Option + Sync + Send, { - pub fn new(mapping_fn: F, stores: Vec) -> Store { - Store { mapping_fn, stores } + pub fn new(mapping_fn: F) -> Store { + Store { mapping_fn } } } @@ -35,16 +33,6 @@ where }) } - fn all_descrs(&self) -> Result, origin::AllDescrsError> { - let mut res = Vec::::new(); - - for store in self.stores.iter() { - store.all_descrs()?.into_iter().collect_into(&mut res); - } - - Ok(res) - } - fn get_file( &self, descr: &origin::Descr,