Remove all_descrs method from origin store

main
Brian Picciano 3 months ago
parent 98ddefad4f
commit b60c849a73
  1. 8
      src/origin.rs
  2. 31
      src/origin/git.rs
  3. 10
      src/origin/git_proxy.rs
  4. 16
      src/origin/mux.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<Vec<Descr>, AllDescrsError>;
fn get_file(&self, descr: &Descr, path: &str) -> Result<util::BoxByteStream, GetFileError>;
}

@ -274,37 +274,6 @@ impl super::Store for FSStore {
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(
&self,
descr: &origin::Descr,

@ -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(
&self,
_descr: &origin::Descr,

@ -3,11 +3,9 @@ use crate::{origin, util};
pub struct Store<F, S>
where
S: origin::Store + Sync + Send + 'static,
F: Fn(&origin::Descr) -> Option<S> + Sync + Send,
{
mapping_fn: F,
stores: Vec<S>,
}
impl<F, S> Store<F, S>
@ -15,8 +13,8 @@ where
S: origin::Store + Sync + Send + 'static,
F: Fn(&origin::Descr) -> Option<S> + Sync + Send,
{
pub fn new(mapping_fn: F, stores: Vec<S>) -> Store<F, S> {
Store { mapping_fn, stores }
pub fn new(mapping_fn: F) -> Store<F, S> {
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(
&self,
descr: &origin::Descr,

Loading…
Cancel
Save