Skip to content

Commit

Permalink
apply for layers
Browse files Browse the repository at this point in the history
  • Loading branch information
koushiro committed Oct 25, 2024
1 parent da92d4c commit 1ebb0bc
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 41 deletions.
10 changes: 7 additions & 3 deletions core/src/layers/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,13 @@ 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()
let info = self.inner.info().as_ref().clone();
let cap = info.full_capability();
info.set_full_capability(Capability {
blocking: true,
..cap
})
.into()
}

async fn create_dir(&self, path: &str, args: OpCreateDir) -> Result<RpCreateDir> {
Expand Down
20 changes: 10 additions & 10 deletions core/src/layers/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,13 @@ 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 cap = meta.full_capability_mut();
if cap.list && cap.write_can_empty {
cap.create_dir = true;
}
meta.into()
let info = (*self.meta).clone();
let cap = info.full_capability();
info.set_full_capability(Capability {
create_dir: cap.list && cap.write_can_empty,
..cap
})
.into()
}

async fn create_dir(&self, path: &str, args: OpCreateDir) -> Result<RpCreateDir> {
Expand Down Expand Up @@ -728,10 +729,9 @@ mod tests {
type BlockingLister = oio::BlockingLister;

fn info(&self) -> Arc<AccessorInfo> {
let mut info = AccessorInfo::default();
info.set_native_capability(self.capability);

info.into()
AccessorInfo::default()
.set_native_capability(self.capability)
.into()
}

async fn create_dir(&self, _: &str, _: OpCreateDir) -> Result<RpCreateDir> {
Expand Down
15 changes: 8 additions & 7 deletions core/src/layers/immutable_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,14 @@ 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()
let info = (*self.inner.info()).clone();
let cap = info.full_capability();
info.set_full_capability(Capability {
list: true,
list_with_recursive: true,
..cap
})
.into()
}

async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> {
Expand Down
25 changes: 12 additions & 13 deletions core/src/layers/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,19 +798,18 @@ mod tests {
type BlockingLister = ();

fn info(&self) -> Arc<AccessorInfo> {
let mut am = AccessorInfo::default();
am.set_native_capability(Capability {
read: true,
write: true,
write_can_multi: true,
stat: true,
list: true,
list_with_recursive: true,
batch: true,
..Default::default()
});

am.into()
AccessorInfo::default()
.set_native_capability(Capability {
read: true,
write: true,
write_can_multi: true,
stat: true,
list: true,
list_with_recursive: true,
batch: true,
..Default::default()
})
.into()
}

async fn stat(&self, _: &str, _: OpStat) -> Result<RpStat> {
Expand Down
15 changes: 7 additions & 8 deletions core/src/layers/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,13 @@ mod tests {
type BlockingLister = ();

fn info(&self) -> Arc<AccessorInfo> {
let mut am = AccessorInfo::default();
am.set_native_capability(Capability {
read: true,
delete: true,
..Default::default()
});

am.into()
AccessorInfo::default()
.set_native_capability(Capability {
read: true,
delete: true,
..Default::default()
})
.into()
}

/// This function will build a reader that always return pending.
Expand Down

0 comments on commit 1ebb0bc

Please sign in to comment.