Skip to content

Commit

Permalink
chore(core/layers): align info method of trait Access and `trait …
Browse files Browse the repository at this point in the history
…LayeredAccess` (#5258)
  • Loading branch information
koushiro authored Nov 5, 2024
1 parent 6cec7b4 commit 259a19e
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 86 deletions.
2 changes: 1 addition & 1 deletion core/src/layers/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl<A: Access> LayeredAccess for BlockingAccessor<A> {
&self.inner
}

fn metadata(&self) -> Arc<AccessorInfo> {
fn info(&self) -> Arc<AccessorInfo> {
let mut meta = self.inner.info().as_ref().clone();
meta.full_capability_mut().blocking = true;
meta.into()
Expand Down
54 changes: 27 additions & 27 deletions core/src/layers/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ impl<A: Access> Layer<A> for CompleteLayer {

fn layer(&self, inner: A) -> Self::LayeredAccess {
CompleteAccessor {
meta: inner.info(),
info: inner.info(),
inner: Arc::new(inner),
}
}
}

/// Provide complete wrapper for backend.
pub struct CompleteAccessor<A: Access> {
meta: Arc<AccessorInfo>,
info: Arc<AccessorInfo>,
inner: Arc<A>,
}

Expand All @@ -130,7 +130,7 @@ impl<A: Access> Debug for CompleteAccessor<A> {

impl<A: Access> CompleteAccessor<A> {
fn new_unsupported_error(&self, op: impl Into<&'static str>) -> Error {
let scheme = self.meta.scheme();
let scheme = self.info.scheme();
let op = op.into();
Error::new(
ErrorKind::Unsupported,
Expand All @@ -140,7 +140,7 @@ impl<A: Access> CompleteAccessor<A> {
}

async fn complete_create_dir(&self, path: &str, args: OpCreateDir) -> Result<RpCreateDir> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if capability.create_dir {
return self.inner().create_dir(path, args).await;
}
Expand All @@ -154,7 +154,7 @@ impl<A: Access> CompleteAccessor<A> {
}

fn complete_blocking_create_dir(&self, path: &str, args: OpCreateDir) -> Result<RpCreateDir> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if capability.create_dir && capability.blocking {
return self.inner().blocking_create_dir(path, args);
}
Expand All @@ -168,7 +168,7 @@ impl<A: Access> CompleteAccessor<A> {
}

async fn complete_stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.stat {
return Err(self.new_unsupported_error(Operation::Stat));
}
Expand Down Expand Up @@ -218,7 +218,7 @@ impl<A: Access> CompleteAccessor<A> {
}

fn complete_blocking_stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.stat {
return Err(self.new_unsupported_error(Operation::Stat));
}
Expand Down Expand Up @@ -271,7 +271,7 @@ impl<A: Access> CompleteAccessor<A> {
path: &str,
args: OpList,
) -> Result<(RpList, CompleteLister<A, A::Lister>)> {
let cap = self.meta.full_capability();
let cap = self.info.full_capability();
if !cap.list {
return Err(self.new_unsupported_error(Operation::List));
}
Expand Down Expand Up @@ -319,7 +319,7 @@ impl<A: Access> CompleteAccessor<A> {
path: &str,
args: OpList,
) -> Result<(RpList, CompleteLister<A, A::BlockingLister>)> {
let cap = self.meta.full_capability();
let cap = self.info.full_capability();
if !cap.list {
return Err(self.new_unsupported_error(Operation::BlockingList));
}
Expand Down Expand Up @@ -377,8 +377,8 @@ 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();
fn info(&self) -> Arc<AccessorInfo> {
let mut meta = (*self.info).clone();
let cap = meta.full_capability_mut();
if cap.list && cap.write_can_empty {
cap.create_dir = true;
Expand All @@ -391,7 +391,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.read {
return Err(self.new_unsupported_error(Operation::Read));
}
Expand All @@ -404,7 +404,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

async fn write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::Writer)> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.write {
return Err(self.new_unsupported_error(Operation::Write));
}
Expand All @@ -413,7 +413,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
ErrorKind::Unsupported,
format!(
"service {} doesn't support operation write with append",
self.info().scheme()
self.info.scheme()
),
));
}
Expand All @@ -424,7 +424,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

async fn copy(&self, from: &str, to: &str, args: OpCopy) -> Result<RpCopy> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.copy {
return Err(self.new_unsupported_error(Operation::Copy));
}
Expand All @@ -433,7 +433,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

async fn rename(&self, from: &str, to: &str, args: OpRename) -> Result<RpRename> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.rename {
return Err(self.new_unsupported_error(Operation::Rename));
}
Expand All @@ -446,7 +446,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

async fn delete(&self, path: &str, args: OpDelete) -> Result<RpDelete> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.delete {
return Err(self.new_unsupported_error(Operation::Delete));
}
Expand All @@ -455,7 +455,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

async fn list(&self, path: &str, args: OpList) -> Result<(RpList, Self::Lister)> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.list {
return Err(self.new_unsupported_error(Operation::List));
}
Expand All @@ -464,7 +464,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

async fn batch(&self, args: OpBatch) -> Result<RpBatch> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.batch {
return Err(self.new_unsupported_error(Operation::Batch));
}
Expand All @@ -473,7 +473,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

async fn presign(&self, path: &str, args: OpPresign) -> Result<RpPresign> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.presign {
return Err(self.new_unsupported_error(Operation::Presign));
}
Expand All @@ -486,7 +486,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

fn blocking_read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::BlockingReader)> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.read || !capability.blocking {
return Err(self.new_unsupported_error(Operation::Read));
}
Expand All @@ -498,7 +498,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

fn blocking_write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::BlockingWriter)> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.write || !capability.blocking {
return Err(self.new_unsupported_error(Operation::BlockingWrite));
}
Expand All @@ -508,7 +508,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
ErrorKind::Unsupported,
format!(
"service {} doesn't support operation write with append",
self.info().scheme()
self.info.scheme()
),
));
}
Expand All @@ -519,7 +519,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

fn blocking_copy(&self, from: &str, to: &str, args: OpCopy) -> Result<RpCopy> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.copy || !capability.blocking {
return Err(self.new_unsupported_error(Operation::BlockingCopy));
}
Expand All @@ -528,7 +528,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

fn blocking_rename(&self, from: &str, to: &str, args: OpRename) -> Result<RpRename> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.rename || !capability.blocking {
return Err(self.new_unsupported_error(Operation::BlockingRename));
}
Expand All @@ -541,7 +541,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

fn blocking_delete(&self, path: &str, args: OpDelete) -> Result<RpDelete> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.delete || !capability.blocking {
return Err(self.new_unsupported_error(Operation::BlockingDelete));
}
Expand All @@ -550,7 +550,7 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

fn blocking_list(&self, path: &str, args: OpList) -> Result<(RpList, Self::BlockingLister)> {
let capability = self.meta.full_capability();
let capability = self.info.full_capability();
if !capability.list || !capability.blocking {
return Err(self.new_unsupported_error(Operation::BlockingList));
}
Expand Down
Loading

0 comments on commit 259a19e

Please sign in to comment.