diff --git a/integrations/unftp-sbe/src/lib.rs b/integrations/unftp-sbe/src/lib.rs index 415c5bc5e76a..43390430afaf 100644 --- a/integrations/unftp-sbe/src/lib.rs +++ b/integrations/unftp-sbe/src/lib.rs @@ -133,6 +133,15 @@ fn convert_path(path: &Path) -> storage::Result<&str> { }) } +fn convert_dir_path(path: &Path) -> storage::Result { + let path_str = convert_path(path)?; + if path_str.ends_with('/') { + Ok(path_str.to_string()) + } else { + Ok(format!("{}/", path_str)) + } +} + #[async_trait::async_trait] impl StorageBackend for OpendalStorage { type Metadata = OpendalMetadata; @@ -160,7 +169,7 @@ impl StorageBackend for OpendalStorage { { let ret = self .op - .list(convert_path(path.as_ref())?) + .list(&convert_dir_path(path.as_ref())?) .await .map_err(convert_err)? .into_iter() @@ -222,11 +231,10 @@ impl StorageBackend for OpendalStorage { } async fn mkd + Send + Debug>(&self, _: &User, path: P) -> storage::Result<()> { - let mut path_str = convert_path(path.as_ref())?.to_string(); - if !path_str.ends_with('/') { - path_str.push('/'); - } - self.op.create_dir(&path_str).await.map_err(convert_err) + self.op + .create_dir(&convert_dir_path(path.as_ref())?) + .await + .map_err(convert_err) } async fn rename + Send + Debug>( @@ -241,7 +249,7 @@ impl StorageBackend for OpendalStorage { async fn rmd + Send + Debug>(&self, _: &User, path: P) -> storage::Result<()> { self.op - .remove_all(convert_path(path.as_ref())?) + .remove_all(&convert_dir_path(path.as_ref())?) .await .map_err(convert_err) } @@ -249,7 +257,7 @@ impl StorageBackend for OpendalStorage { async fn cwd + Send + Debug>(&self, _: &User, path: P) -> storage::Result<()> { use opendal::ErrorKind::*; - match self.op.stat(convert_path(path.as_ref())?).await { + match self.op.stat(&convert_dir_path(path.as_ref())?).await { Ok(_) => Ok(()), Err(e) if matches!(e.kind(), NotFound | NotADirectory) => Err(storage::Error::new( storage::ErrorKind::PermanentDirectoryNotAvailable,