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 5 commits into
base: main
Choose a base branch
from
Draft
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
10 changes: 6 additions & 4 deletions core/src/layers/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,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 @@ -156,7 +160,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 @@ -174,9 +178,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
17 changes: 9 additions & 8 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 @@ -376,14 +383,8 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
&self.inner
}

// 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 cap = meta.full_capability_mut();
if cap.list && cap.write_can_empty {
cap.create_dir = true;
}
meta.into()
self.meta.clone()
}

async fn create_dir(&self, path: &str, args: OpCreateDir) -> Result<RpCreateDir> {
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 @@ -74,8 +74,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 @@ -84,6 +91,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 @@ -150,13 +158,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