This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 6493567be refactor: Split capability check to seperate layer (#6952)
6493567be is described below

commit 6493567be93dd8349b79a77df492d7043afedf6e
Author: Xuanwo <[email protected]>
AuthorDate: Mon Dec 8 20:24:39 2025 +0800

    refactor: Split capability check to seperate layer (#6952)
    
    * refactor: Split capability check to seperate layer
    
    Signed-off-by: Xuanwo <[email protected]>
    
    * follow pattern
    
    Signed-off-by: Xuanwo <[email protected]>
    
    ---------
    
    Signed-off-by: Xuanwo <[email protected]>
---
 core/Cargo.lock                                    |  9 +++++
 core/Cargo.toml                                    | 11 ++++++-
 core/core/src/layers/correctness_check.rs          | 10 +++---
 core/core/src/layers/mod.rs                        |  2 --
 core/layers/capability-check/Cargo.toml            | 37 +++++++++++++++++++++
 .../capability-check/src/lib.rs}                   | 38 ++++++++++++++--------
 core/src/lib.rs                                    |  2 ++
 7 files changed, 88 insertions(+), 21 deletions(-)

diff --git a/core/Cargo.lock b/core/Cargo.lock
index 323d25441..baa1b2579 100644
--- a/core/Cargo.lock
+++ b/core/Cargo.lock
@@ -5477,6 +5477,7 @@ dependencies = [
  "opendal-core",
  "opendal-layer-async-backtrace",
  "opendal-layer-await-tree",
+ "opendal-layer-capability-check",
  "opendal-service-aliyun-drive",
  "opendal-service-azblob",
  "opendal-service-azdls",
@@ -5667,6 +5668,14 @@ dependencies = [
  "opendal-core",
 ]
 
+[[package]]
+name = "opendal-layer-capability-check"
+version = "0.55.0"
+dependencies = [
+ "opendal-core",
+ "tokio",
+]
+
 [[package]]
 name = "opendal-service-aliyun-drive"
 version = "0.55.0"
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 9585da63c..d087b0414 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -27,6 +27,8 @@ members = [
   "services/aliyun-drive",
   "services/*",
   "layers/*",
+  "layers/await-tree",
+  "layers/capability-check",
 ]
 
 [workspace.package]
@@ -78,12 +80,18 @@ all-features = true
 
 [features]
 blocking = ["opendal-core/blocking"]
-default = ["reqwest-rustls-tls", "executors-tokio", "services-memory"]
+default = [
+  "reqwest-rustls-tls",
+  "executors-tokio",
+  "services-memory",
+  "layers-capability-check",
+]
 executors-tokio = ["opendal-core/executors-tokio"]
 internal-path-cache = ["opendal-core/internal-path-cache"]
 internal-tokio-rt = ["opendal-core/internal-tokio-rt"]
 layers-async-backtrace = ["dep:opendal-layer-async-backtrace"]
 layers-await-tree = ["dep:opendal-layer-await-tree"]
+layers-capability-check = ["dep:opendal-layer-capability-check"]
 layers-chaos = ["opendal-core/layers-chaos"]
 layers-dtrace = ["opendal-core/layers-dtrace"]
 layers-fastmetrics = ["opendal-core/layers-fastmetrics"]
@@ -184,6 +192,7 @@ required-features = ["tests"]
 opendal-core = { path = "core", version = "0.55.0", default-features = false }
 opendal-layer-async-backtrace = { path = "layers/async-backtrace", version = 
"0.55.0", optional = true, default-features = false }
 opendal-layer-await-tree = { path = "layers/await-tree", version = "0.55.0", 
optional = true, default-features = false }
+opendal-layer-capability-check = { path = "layers/capability-check", version = 
"0.55.0", optional = true, default-features = false }
 opendal-service-aliyun-drive = { path = "services/aliyun-drive", version = 
"0.55.0", optional = true, default-features = false }
 opendal-service-azblob = { path = "services/azblob", version = "0.55.0", 
optional = true, default-features = false }
 opendal-service-azdls = { path = "services/azdls", version = "0.55.0", 
optional = true, default-features = false }
diff --git a/core/core/src/layers/correctness_check.rs 
b/core/core/src/layers/correctness_check.rs
index 57b8dada4..38e211def 100644
--- a/core/core/src/layers/correctness_check.rs
+++ b/core/core/src/layers/correctness_check.rs
@@ -51,6 +51,11 @@ impl<A: Access> Layer<A> for CorrectnessCheckLayer {
     }
 }
 
+pub struct CorrectnessAccessor<A: Access> {
+    info: Arc<AccessorInfo>,
+    inner: A,
+}
+
 pub(crate) fn new_unsupported_error(info: &AccessorInfo, op: Operation, args: 
&str) -> Error {
     let scheme = info.scheme();
     let op = op.into_static();
@@ -62,11 +67,6 @@ pub(crate) fn new_unsupported_error(info: &AccessorInfo, op: 
Operation, args: &s
     .with_operation(op)
 }
 
-pub struct CorrectnessAccessor<A: Access> {
-    info: Arc<AccessorInfo>,
-    inner: A,
-}
-
 impl<A: Access> Debug for CorrectnessAccessor<A> {
     fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
         f.debug_struct("CorrectnessCheckAccessor")
diff --git a/core/core/src/layers/mod.rs b/core/core/src/layers/mod.rs
index 09ae0d760..85cccd55b 100644
--- a/core/core/src/layers/mod.rs
+++ b/core/core/src/layers/mod.rs
@@ -120,8 +120,6 @@ pub mod observe;
 
 mod correctness_check;
 pub(crate) use correctness_check::CorrectnessCheckLayer;
-mod capability_check;
-pub use capability_check::CapabilityCheckLayer;
 
 mod http_client;
 pub use http_client::HttpClientLayer;
diff --git a/core/layers/capability-check/Cargo.toml 
b/core/layers/capability-check/Cargo.toml
new file mode 100644
index 000000000..933937c18
--- /dev/null
+++ b/core/layers/capability-check/Cargo.toml
@@ -0,0 +1,37 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+[package]
+description = "Apache OpenDAL capability-check layer"
+name = "opendal-layer-capability-check"
+
+authors = { workspace = true }
+edition = { workspace = true }
+homepage = { workspace = true }
+license = { workspace = true }
+repository = { workspace = true }
+rust-version = { workspace = true }
+version = { workspace = true }
+
+[package.metadata.docs.rs]
+all-features = true
+
+[dependencies]
+opendal-core = { path = "../../core", version = "0.55.0", default-features = 
false }
+
+[dev-dependencies]
+tokio = { workspace = true, features = ["macros", "rt"] }
diff --git a/core/core/src/layers/capability_check.rs 
b/core/layers/capability-check/src/lib.rs
similarity index 84%
rename from core/core/src/layers/capability_check.rs
rename to core/layers/capability-check/src/lib.rs
index d84de68df..5d09ef1ae 100644
--- a/core/core/src/layers/capability_check.rs
+++ b/core/layers/capability-check/src/lib.rs
@@ -19,8 +19,8 @@ use std::fmt::Debug;
 use std::fmt::Formatter;
 use std::sync::Arc;
 
-use crate::layers::correctness_check::new_unsupported_error;
-use crate::raw::*;
+use opendal_core::raw::*;
+use opendal_core::{Error, ErrorKind, Result};
 
 /// Add an extra capability check layer for every operation
 ///
@@ -41,13 +41,13 @@ use crate::raw::*;
 /// # examples
 ///
 /// ```no_run
-/// # use opendal_core::layers::CapabilityCheckLayer;
+/// # use opendal_layer_capability_check::CapabilityCheckLayer;
 /// # use opendal_core::services;
 /// # use opendal_core::Operator;
 /// # use opendal_core::Result;
 ///
 /// # fn main() -> Result<()> {
-/// use opendal_core::layers::CapabilityCheckLayer;
+/// use opendal_layer_capability_check::CapabilityCheckLayer;
 /// let _ = Operator::new(services::Memory::default())?
 ///     .layer(CapabilityCheckLayer)
 ///     .finish();
@@ -66,11 +66,23 @@ impl<A: Access> Layer<A> for CapabilityCheckLayer {
         CapabilityAccessor { info, inner }
     }
 }
+
 pub struct CapabilityAccessor<A: Access> {
     info: Arc<AccessorInfo>,
     inner: A,
 }
 
+fn new_unsupported_error(info: &AccessorInfo, op: Operation, args: &str) -> 
Error {
+    let scheme = info.scheme();
+    let op = op.into_static();
+
+    Error::new(
+        ErrorKind::Unsupported,
+        format!("The service {scheme} does not support the operation {op} with 
the arguments {args}. Please verify if the relevant flags have been enabled, or 
submit an issue if you believe this is incorrect."),
+    )
+    .with_operation(op)
+}
+
 impl<A: Access> Debug for CapabilityAccessor<A> {
     fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
         f.debug_struct("CapabilityCheckAccessor")
@@ -90,11 +102,11 @@ impl<A: Access> LayeredAccess for CapabilityAccessor<A> {
         &self.inner
     }
 
-    async fn read(&self, path: &str, args: OpRead) -> crate::Result<(RpRead, 
Self::Reader)> {
+    async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, 
Self::Reader)> {
         self.inner.read(path, args).await
     }
 
-    async fn write(&self, path: &str, args: OpWrite) -> 
crate::Result<(RpWrite, Self::Writer)> {
+    async fn write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, 
Self::Writer)> {
         let capability = self.info.full_capability();
         if !capability.write_with_content_type && 
args.content_type().is_some() {
             return Err(new_unsupported_error(
@@ -121,11 +133,11 @@ impl<A: Access> LayeredAccess for CapabilityAccessor<A> {
         self.inner.write(path, args).await
     }
 
-    async fn delete(&self) -> crate::Result<(RpDelete, Self::Deleter)> {
+    async fn delete(&self) -> Result<(RpDelete, Self::Deleter)> {
         self.inner.delete().await
     }
 
-    async fn list(&self, path: &str, args: OpList) -> crate::Result<(RpList, 
Self::Lister)> {
+    async fn list(&self, path: &str, args: OpList) -> Result<(RpList, 
Self::Lister)> {
         let capability = self.info.full_capability();
         if !capability.list_with_versions && args.versions() {
             return Err(new_unsupported_error(
@@ -142,9 +154,9 @@ impl<A: Access> LayeredAccess for CapabilityAccessor<A> {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::Capability;
-    use crate::ErrorKind;
-    use crate::Operator;
+    use opendal_core::Capability;
+    use opendal_core::ErrorKind;
+    use opendal_core::Operator;
 
     #[derive(Debug)]
     struct MockService {
@@ -164,11 +176,11 @@ mod tests {
             info.into()
         }
 
-        async fn write(&self, _: &str, _: OpWrite) -> crate::Result<(RpWrite, 
Self::Writer)> {
+        async fn write(&self, _: &str, _: OpWrite) -> Result<(RpWrite, 
Self::Writer)> {
             Ok((RpWrite::new(), Box::new(())))
         }
 
-        async fn list(&self, _: &str, _: OpList) -> crate::Result<(RpList, 
Self::Lister)> {
+        async fn list(&self, _: &str, _: OpList) -> Result<(RpList, 
Self::Lister)> {
             Ok((RpList {}, Box::new(())))
         }
     }
diff --git a/core/src/lib.rs b/core/src/lib.rs
index 26b61e08d..c6872d9c7 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -50,4 +50,6 @@ pub mod layers {
     pub use opendal_layer_async_backtrace::*;
     #[cfg(feature = "layers-await-tree")]
     pub use opendal_layer_await_tree::*;
+    #[cfg(feature = "layers-capability-check")]
+    pub use opendal_layer_capability_check::*;
 }

Reply via email to