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(core): move move logic from fn metadata(&self) -> Arc<AccessorInfo> to impl<A: Access> Layer<A> for CompleteLayer #4896

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
10 changes: 6 additions & 4 deletions core/src/layers/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,12 @@ impl<A: Access> Layer<A> for BlockingLayer {
type LayeredAccess = BlockingAccessor<A>;

fn layer(&self, inner: A) -> Self::LayeredAccess {
let mut meta = inner.info().as_ref().clone();
meta.full_capability_mut().blocking = true;

BlockingAccessor {
inner,
meta: Arc::new(meta),
handle: self.handle.clone(),
}
}
Expand All @@ -163,7 +167,7 @@ impl<A: Access> Layer<A> for BlockingLayer {
#[derive(Clone, Debug)]
pub struct BlockingAccessor<A: Access> {
inner: A,

meta: Arc<AccessorInfo>,
handle: Handle,
}

Expand All @@ -181,9 +185,7 @@ impl<A: Access> LayeredAccess for BlockingAccessor<A> {
}

fn metadata(&self) -> Arc<AccessorInfo> {
let mut meta = self.inner.info().as_ref().clone();
meta.full_capability_mut().blocking = true;
meta.into()
self.meta.clone()
}

async fn create_dir(&self, path: &str, args: OpCreateDir) -> Result<RpCreateDir> {
Expand Down
11 changes: 9 additions & 2 deletions core/src/layers/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,15 @@ impl<A: Access> Layer<A> for CompleteLayer {
type LayeredAccess = CompleteAccessor<A>;

fn layer(&self, inner: A) -> Self::LayeredAccess {
let mut meta = inner.info().as_ref().clone();
let cap = meta.full_capability_mut();

if cap.list && cap.write_can_empty {
cap.create_dir = true;
}

CompleteAccessor {
meta: inner.info(),
meta: meta.into(),
inner: Arc::new(inner),
}
}
Expand Down Expand Up @@ -382,7 +389,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {

// Todo: May move the logic to the implement of Layer::layer of CompleteAccessor<A>
fn metadata(&self) -> Arc<AccessorInfo> {
let mut meta = (*self.meta).clone();
let mut meta = self.meta.as_ref().clone();
let cap = meta.full_capability_mut();
if cap.list && cap.write_can_empty {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can remove those code and the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we do this, the issue #4888 is not resolved....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we do this, the issue #4888 is not resolved....

Could you elaborate further? I'm not sure which issue remains unresolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can remove those code and the comment?

you means delete the

// Todo: May move the logic to the implement of Layer::layer of CompleteAccessor<A>

and

let mut meta = self.meta.as_ref().clone();

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, since we have created the Arc<AccessInfo> during layer(), we can remove the dup code here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's my problem, sry.

cap.create_dir = true;
Expand Down
16 changes: 9 additions & 7 deletions core/src/layers/immutable_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ impl<A: Access> Layer<A> for ImmutableIndexLayer {
type LayeredAccess = ImmutableIndexAccessor<A>;

fn layer(&self, inner: A) -> Self::LayeredAccess {
let mut meta = inner.info().as_ref().clone();

let cap = meta.full_capability_mut();
cap.list = true;
cap.list_with_recursive = true;

ImmutableIndexAccessor {
vec: self.vec.clone(),
meta: Arc::new(meta),
inner,
}
}
Expand All @@ -81,6 +88,7 @@ impl<A: Access> Layer<A> for ImmutableIndexLayer {
#[derive(Debug, Clone)]
pub struct ImmutableIndexAccessor<A: Access> {
inner: A,
meta: Arc<AccessorInfo>,
vec: Vec<String>,
}

Expand Down Expand Up @@ -147,13 +155,7 @@ impl<A: Access> LayeredAccess for ImmutableIndexAccessor<A> {

/// Add list capabilities for underlying storage services.
fn metadata(&self) -> Arc<AccessorInfo> {
let mut meta = (*self.inner.info()).clone();

let cap = meta.full_capability_mut();
cap.list = true;
cap.list_with_recursive = true;

meta.into()
self.meta.clone()
}

async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> {
Expand Down
Loading