Remove all_descrs method from origin store

This commit is contained in:
Brian Picciano 2024-01-22 16:48:57 +01:00
parent 98ddefad4f
commit b60c849a73
4 changed files with 2 additions and 63 deletions

View File

@ -25,12 +25,6 @@ pub enum SyncError {
Unexpected(#[from] unexpected::Error), Unexpected(#[from] unexpected::Error),
} }
#[derive(thiserror::Error, Clone, Debug, PartialEq)]
pub enum AllDescrsError {
#[error(transparent)]
Unexpected(#[from] unexpected::Error),
}
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub enum GetFileError { pub enum GetFileError {
#[error("descr not synced")] #[error("descr not synced")]
@ -52,7 +46,5 @@ pub trait Store {
/// the origin into the storage. /// the origin into the storage.
fn sync(&self, descr: &Descr) -> util::BoxFuture<'_, Result<(), SyncError>>; fn sync(&self, descr: &Descr) -> util::BoxFuture<'_, Result<(), SyncError>>;
fn all_descrs(&self) -> Result<Vec<Descr>, AllDescrsError>;
fn get_file(&self, descr: &Descr, path: &str) -> Result<util::BoxByteStream, GetFileError>; fn get_file(&self, descr: &Descr, path: &str) -> Result<util::BoxByteStream, GetFileError>;
} }

View File

@ -274,37 +274,6 @@ impl super::Store for FSStore {
Box::pin(future::ready(res)) Box::pin(future::ready(res))
} }
fn all_descrs(&self) -> Result<Vec<origin::Descr>, origin::AllDescrsError> {
fs::read_dir(&self.dir_path).or_unexpected()?.map(
|dir_entry_res: io::Result<fs::DirEntry>| -> Result<origin::Descr, origin::AllDescrsError> {
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( fn get_file(
&self, &self,
descr: &origin::Descr, descr: &origin::Descr,

View File

@ -168,16 +168,6 @@ impl origin::Store for Proxy {
}) })
} }
fn all_descrs(&self) -> Result<Vec<origin::Descr>, origin::AllDescrsError> {
Ok(self
.state
.read()
.unwrap()
.keys()
.map(|d| d.clone())
.collect())
}
fn get_file( fn get_file(
&self, &self,
_descr: &origin::Descr, _descr: &origin::Descr,

View File

@ -3,11 +3,9 @@ use crate::{origin, util};
pub struct Store<F, S> pub struct Store<F, S>
where where
S: origin::Store + Sync + Send + 'static,
F: Fn(&origin::Descr) -> Option<S> + Sync + Send, F: Fn(&origin::Descr) -> Option<S> + Sync + Send,
{ {
mapping_fn: F, mapping_fn: F,
stores: Vec<S>,
} }
impl<F, S> Store<F, S> impl<F, S> Store<F, S>
@ -15,8 +13,8 @@ where
S: origin::Store + Sync + Send + 'static, S: origin::Store + Sync + Send + 'static,
F: Fn(&origin::Descr) -> Option<S> + Sync + Send, F: Fn(&origin::Descr) -> Option<S> + Sync + Send,
{ {
pub fn new(mapping_fn: F, stores: Vec<S>) -> Store<F, S> { pub fn new(mapping_fn: F) -> Store<F, S> {
Store { mapping_fn, stores } Store { mapping_fn }
} }
} }
@ -35,16 +33,6 @@ where
}) })
} }
fn all_descrs(&self) -> Result<Vec<origin::Descr>, origin::AllDescrsError> {
let mut res = Vec::<origin::Descr>::new();
for store in self.stores.iter() {
store.all_descrs()?.into_iter().collect_into(&mut res);
}
Ok(res)
}
fn get_file( fn get_file(
&self, &self,
descr: &origin::Descr, descr: &origin::Descr,