Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Merge compose_{read,write} into enum_utils #3871

Merged
merged 3 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 13 additions & 52 deletions core/src/layers/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use async_trait::async_trait;
use crate::raw::oio::BufferReader;
use crate::raw::oio::FileReader;
use crate::raw::oio::FlatLister;
use crate::raw::oio::FourWaysReader;
use crate::raw::oio::LazyReader;
use crate::raw::oio::PrefixLister;
use crate::raw::oio::RangeReader;
Expand Down Expand Up @@ -384,19 +383,19 @@ impl<A: Accessor> CompleteAccessor<A> {
// - If service can list_with_recursive, we can forward list to it directly.
(_, true) => {
let (rp, p) = self.inner.list(path, args).await?;
Ok((rp, CompleteLister::AlreadyComplete(p)))
Ok((rp, CompleteLister::One(p)))
}
// If recursive is true but service can't list_with_recursive
(true, false) => {
// Forward path that ends with /
if path.ends_with('/') {
let p = FlatLister::new(self.inner.clone(), path);
Ok((RpList::default(), CompleteLister::NeedFlat(p)))
Ok((RpList::default(), CompleteLister::Two(p)))
} else {
let parent = get_parent(path);
let p = FlatLister::new(self.inner.clone(), parent);
let p = PrefixLister::new(p, path);
Ok((RpList::default(), CompleteLister::Both(p)))
Ok((RpList::default(), CompleteLister::Four(p)))
}
}
// If recursive and service doesn't support list_with_recursive, we need to handle
Expand All @@ -405,12 +404,12 @@ impl<A: Accessor> CompleteAccessor<A> {
// Forward path that ends with /
if path.ends_with('/') {
let (rp, p) = self.inner.list(path, args).await?;
Ok((rp, CompleteLister::AlreadyComplete(p)))
Ok((rp, CompleteLister::One(p)))
} else {
let parent = get_parent(path);
let (rp, p) = self.inner.list(parent, args).await?;
let p = PrefixLister::new(p, path);
Ok((rp, CompleteLister::NeedPrefix(p)))
Ok((rp, CompleteLister::Three(p)))
}
}
}
Expand All @@ -432,19 +431,19 @@ impl<A: Accessor> CompleteAccessor<A> {
// - If service can list_with_recursive, we can forward list to it directly.
(_, true) => {
let (rp, p) = self.inner.blocking_list(path, args)?;
Ok((rp, CompleteLister::AlreadyComplete(p)))
Ok((rp, CompleteLister::One(p)))
}
// If recursive is true but service can't list_with_recursive
(true, false) => {
// Forward path that ends with /
if path.ends_with('/') {
let p = FlatLister::new(self.inner.clone(), path);
Ok((RpList::default(), CompleteLister::NeedFlat(p)))
Ok((RpList::default(), CompleteLister::Two(p)))
} else {
let parent = get_parent(path);
let p = FlatLister::new(self.inner.clone(), parent);
let p = PrefixLister::new(p, path);
Ok((RpList::default(), CompleteLister::Both(p)))
Ok((RpList::default(), CompleteLister::Four(p)))
}
}
// If recursive and service doesn't support list_with_recursive, we need to handle
Expand All @@ -453,12 +452,12 @@ impl<A: Accessor> CompleteAccessor<A> {
// Forward path that ends with /
if path.ends_with('/') {
let (rp, p) = self.inner.blocking_list(path, args)?;
Ok((rp, CompleteLister::AlreadyComplete(p)))
Ok((rp, CompleteLister::One(p)))
} else {
let parent = get_parent(path);
let (rp, p) = self.inner.blocking_list(parent, args)?;
let p = PrefixLister::new(p, path);
Ok((rp, CompleteLister::NeedPrefix(p)))
Ok((rp, CompleteLister::Three(p)))
}
}
}
Expand Down Expand Up @@ -676,53 +675,15 @@ impl<A: Accessor> LayeredAccessor for CompleteAccessor<A> {
pub type CompleteReader<A, R> =
TwoWays<InnerCompleteReader<A, R>, BufferReader<InnerCompleteReader<A, R>>>;

type InnerCompleteReader<A, R> = FourWaysReader<
type InnerCompleteReader<A, R> = FourWays<
LazyReader<A, R>,
FileReader<A, R>,
RangeReader<A, R>,
StreamableReader<RangeReader<A, R>>,
>;

pub enum CompleteLister<A: Accessor, P> {
AlreadyComplete(P),
NeedFlat(FlatLister<Arc<A>, P>),
NeedPrefix(PrefixLister<P>),
Both(PrefixLister<FlatLister<Arc<A>, P>>),
}

impl<A, P> oio::List for CompleteLister<A, P>
where
A: Accessor<Lister = P>,
P: oio::List,
{
fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Result<Option<oio::Entry>>> {
use CompleteLister::*;

match self {
AlreadyComplete(p) => p.poll_next(cx),
NeedFlat(p) => p.poll_next(cx),
NeedPrefix(p) => p.poll_next(cx),
Both(p) => p.poll_next(cx),
}
}
}

impl<A, P> oio::BlockingList for CompleteLister<A, P>
where
A: Accessor<BlockingLister = P>,
P: oio::BlockingList,
{
fn next(&mut self) -> Result<Option<oio::Entry>> {
use CompleteLister::*;

match self {
AlreadyComplete(p) => p.next(),
NeedFlat(p) => p.next(),
NeedPrefix(p) => p.next(),
Both(p) => p.next(),
}
}
}
pub type CompleteLister<A, P> =
FourWays<P, FlatLister<Arc<A>, P>, PrefixLister<P>, PrefixLister<FlatLister<Arc<A>, P>>>;

pub struct CompleteWriter<W> {
inner: Option<W>,
Expand Down
Loading
Loading