diff --git a/src/api.rs b/src/api.rs index c531a734041..c94a784caed 100644 --- a/src/api.rs +++ b/src/api.rs @@ -17,6 +17,32 @@ mod macros; // // At minimum, we don't want to list the indices (may need proc-macro) +#[derive(Clone, Eq, PartialEq, Debug, serde::Serialize, serde::Deserialize)] +pub enum NotBefore { + /// Start iteration at the beginning of the directory + None, + /// Start iteration at an exact match with the provided filename + Filename(PathBuf), + /// Start iteration at the first path that is "after" the provided filename + FilenamePart(PathBuf), +} + +impl NotBefore { + pub fn with_filename(value: Option) -> Self { + match value { + None => Self::None, + Some(p) => Self::Filename(p), + } + } + + pub fn with_filename_part(value: Option) -> Self { + match value { + None => Self::None, + Some(p) => Self::FilenamePart(p), + } + } +} + generate_enums! { //////////// @@ -244,7 +270,7 @@ pub mod request { ReadDirFirst: - location: Location - dir: PathBuf - - not_before: Option<(PathBuf, bool)> + - not_before: NotBefore ReadDirNext: diff --git a/src/client.rs b/src/client.rs index ed9a9ec8daf..65106eab2a8 100644 --- a/src/client.rs +++ b/src/client.rs @@ -610,7 +610,7 @@ pub trait FilesystemClient: PollClient { self.request(request::ReadDirFirst { location, dir, - not_before: not_before_filename.map(|p| (p, true)), + not_before: NotBefore::with_filename(not_before_filename), }) } @@ -630,7 +630,7 @@ pub trait FilesystemClient: PollClient { self.request(request::ReadDirFirst { location, dir, - not_before: not_before_filename.map(|p| (p, false)), + not_before: NotBefore::with_filename_part(not_before_filename), }) } diff --git a/src/service.rs b/src/service.rs index 766bcc03096..c9dcaf8be6a 100644 --- a/src/service.rs +++ b/src/service.rs @@ -409,10 +409,7 @@ impl ServiceResources

{ let maybe_entry = match filestore.read_dir_first( &request.dir, request.location, - request - .not_before - .as_ref() - .map(|(path, require_equal)| (&**path, *require_equal)), + &request.not_before, )? { Some((entry, read_dir_state)) => { ctx.read_dir_state = Some(read_dir_state); diff --git a/src/store/filestore.rs b/src/store/filestore.rs index 26520c235f7..12cf2fffa00 100644 --- a/src/store/filestore.rs +++ b/src/store/filestore.rs @@ -1,6 +1,7 @@ use core::cmp::Ordering; use crate::{ + api::NotBefore, error::{Error, Result}, // service::ReadDirState, store::{self, DynFilesystem, Store}, @@ -119,7 +120,7 @@ pub trait Filestore { &mut self, dir: &Path, location: Location, - not_before: Option<(&Path, bool)>, + not_before: &NotBefore, ) -> Result>; /// Continue iterating over entries of a directory. @@ -155,7 +156,7 @@ impl ClientFilestore { &mut self, clients_dir: &Path, location: Location, - not_before: Option<(&Path, bool)>, + not_before: &NotBefore, ) -> Result> { let fs = self.store.fs(location); let dir = self.actual_path(clients_dir)?; @@ -172,19 +173,13 @@ impl ClientFilestore { // Option> -> ?? .map(|(i, entry)| (i, entry.unwrap())) // if there is a "not_before" entry, skip all entries before it. - .find(|(_, entry)| { - if let Some((not_before, require_equal)) = not_before { - if require_equal { - entry.file_name() == not_before - } else { - match entry.file_name().cmp_str(not_before) { - Ordering::Less => false, - Ordering::Equal | Ordering::Greater => true, - } - } - } else { - true - } + .find(|(_, entry)| match not_before { + NotBefore::None => true, + NotBefore::Filename(path) => entry.file_name() == &**path, + NotBefore::FilenamePart(path) => match entry.file_name().cmp_str(path) { + Ordering::Less => false, + Ordering::Equal | Ordering::Greater => true, + }, }) // if there is an entry, construct the state that needs storing out of it, // remove the prefix from the entry's path to not leak implementation details to @@ -446,7 +441,7 @@ impl Filestore for ClientFilestore { &mut self, clients_dir: &Path, location: Location, - not_before: Option<(&Path, bool)>, + not_before: &NotBefore, ) -> Result> { self.read_dir_first_impl(clients_dir, location, not_before) }