Skip to content

Commit

Permalink
feat(core): add copy&rename to error_context layer
Browse files Browse the repository at this point in the history
Signed-off-by: suyanhanx <suyanhanx@gmail.com>
  • Loading branch information
suyanhanx committed Apr 19, 2023
1 parent 9751188 commit 705d761
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
42 changes: 42 additions & 0 deletions core/src/layers/error_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,30 @@ impl<A: Accessor> LayeredAccessor for ErrorContextAccessor<A> {
.await
}

async fn copy(&self, from: &str, to: &str, args: OpCopy) -> Result<RpCopy> {
self.inner
.copy(from, to, args)
.map_err(|err| {
err.with_operation(Operation::Copy)
.with_context("service", self.meta.scheme())
.with_context("from", from)
.with_context("to", to)
})
.await
}

async fn rename(&self, from: &str, to: &str, args: OpRename) -> Result<RpRename> {
self.inner
.rename(from, to, args)
.map_err(|err| {
err.with_operation(Operation::Rename)
.with_context("service", self.meta.scheme())
.with_context("from", from)
.with_context("to", to)
})
.await
}

async fn stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
self.inner
.stat(path, args)
Expand Down Expand Up @@ -284,6 +308,24 @@ impl<A: Accessor> LayeredAccessor for ErrorContextAccessor<A> {
})
}

fn blocking_copy(&self, from: &str, to: &str, args: OpCopy) -> Result<RpCopy> {
self.inner.blocking_copy(from, to, args).map_err(|err| {
err.with_operation(Operation::BlockingCopy)
.with_context("service", self.meta.scheme())
.with_context("from", from)
.with_context("to", to)
})
}

fn blocking_rename(&self, from: &str, to: &str, args: OpRename) -> Result<RpRename> {
self.inner.blocking_rename(from, to, args).map_err(|err| {
err.with_operation(Operation::BlockingRename)
.with_context("service", self.meta.scheme())
.with_context("from", from)
.with_context("to", to)
})
}

fn blocking_stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
self.inner.blocking_stat(path, args).map_err(|err| {
err.with_operation(Operation::BlockingStat)
Expand Down
6 changes: 3 additions & 3 deletions core/src/layers/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ impl<A: Accessor> LayeredAccessor for LoggingAccessor<A> {
target: LOGGING_TARGET,
"service={} operation={} from={} to={} -> started",
self.scheme,
Operation::BlockingMove,
Operation::BlockingRename,
from,
to,
);
Expand All @@ -839,7 +839,7 @@ impl<A: Accessor> LayeredAccessor for LoggingAccessor<A> {
target: LOGGING_TARGET,
"service={} operation={} from={} to={} -> finished",
self.scheme,
Operation::BlockingMove,
Operation::BlockingRename,
from,
to,
);
Expand All @@ -852,7 +852,7 @@ impl<A: Accessor> LayeredAccessor for LoggingAccessor<A> {
lvl,
"service={} operation={} from={} to={} -> {}: {err:?}",
self.scheme,
Operation::BlockingMove,
Operation::BlockingRename,
from,
to,
self.err_status(&err)
Expand Down
4 changes: 2 additions & 2 deletions core/src/raw/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum Operation {
/// Operation for [`crate::raw::Accessor::blocking_copy`]
BlockingCopy,
/// Operation for [`crate::raw::Accessor::blocking_rename`]
BlockingMove,
BlockingRename,
/// Operation for [`crate::raw::Accessor::blocking_stat`]
BlockingStat,
/// Operation for [`crate::raw::Accessor::blocking_delete`]
Expand Down Expand Up @@ -99,7 +99,7 @@ impl From<Operation> for &'static str {
Operation::BlockingRead => "blocking_read",
Operation::BlockingWrite => "blocking_write",
Operation::BlockingCopy => "blocking_copy",
Operation::BlockingMove => "blocking_rename",
Operation::BlockingRename => "blocking_rename",
Operation::BlockingStat => "blocking_stat",
Operation::BlockingDelete => "blocking_delete",
Operation::BlockingList => "blocking_list",
Expand Down
2 changes: 1 addition & 1 deletion core/tests/behavior/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Test specific backend(such as `fs`).
cargo test services_fs
```

As `cargo test` only run tests containing the following string in their names, we use `services-fs` to run all tests under `services::fs`.
As `cargo test` only run tests containing the following string in their names, we use `services_fs` to run all tests under `services::fs`.

To run all tests under `tests/behavior/write.rs` for `fs`, we use `services_fs_write`.

Expand Down

0 comments on commit 705d761

Please sign in to comment.