diff --git a/src/io_util/http_client.rs b/src/io_util/http_client.rs index 0d608971294..ce49bce6028 100644 --- a/src/io_util/http_client.rs +++ b/src/io_util/http_client.rs @@ -12,10 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -use percent_encoding::{utf8_percent_encode, AsciiSet, NON_ALPHANUMERIC}; use std::io::ErrorKind; use std::ops::Deref; +use percent_encoding::utf8_percent_encode; +use percent_encoding::AsciiSet; +use percent_encoding::NON_ALPHANUMERIC; + /// HttpClient that used across opendal. /// /// NOTE: we could change or support more underlying http backend. diff --git a/src/operator.rs b/src/operator.rs index 0d4d7b91189..f701534e12f 100644 --- a/src/operator.rs +++ b/src/operator.rs @@ -14,11 +14,13 @@ #[cfg(feature = "retry")] use std::fmt::Debug; +use std::io::ErrorKind; use std::io::Result; use std::sync::Arc; #[cfg(feature = "retry")] use backon::Backoff; +use futures::StreamExt; use futures::TryStreamExt; use log::debug; @@ -156,8 +158,7 @@ impl Operator { /// Check if this operator can work correctly. /// - /// We will send a real `stat` request to path and return any errors - /// we met. + /// We will send a `list` request to path and return any errors we met. /// /// ``` /// # use std::sync::Arc; @@ -170,15 +171,17 @@ impl Operator { /// # async fn main() -> Result<()> { /// # let accessor = fs::Backend::build().finish().await?; /// let op = Operator::new(accessor); - /// op.check(".opendal").await?; + /// op.check().await?; /// # Ok(()) /// # } /// ``` - pub async fn check(&self, path: &str) -> Result<()> { - // The existences of `.opendal` doesn't matters. - let _ = self.object(path).is_exist().await?; + pub async fn check(&self) -> Result<()> { + let mut ds = self.object("/").list().await?; - Ok(()) + match ds.next().await { + Some(Err(e)) if e.kind() != ErrorKind::NotFound => Err(e), + _ => Ok(()), + } } } diff --git a/tests/behavior/behavior.rs b/tests/behavior/behavior.rs index 0baf31a9fc6..ade4d1a580f 100644 --- a/tests/behavior/behavior.rs +++ b/tests/behavior/behavior.rs @@ -134,9 +134,9 @@ cfg_if::cfg_if! { } } -/// Create file with file path should succeed. +/// Check should be OK. async fn test_check(op: Operator) -> Result<()> { - op.check(".opendal").await.expect("operator check is ok"); + op.check().await.expect("operator check is ok"); Ok(()) }