From f78661f7a71526dde1f7f4479e2d07b3ef5323ed Mon Sep 17 00:00:00 2001 From: Frank Wang <1454884738@qq.com> Date: Thu, 5 Dec 2024 18:27:46 +0000 Subject: [PATCH 1/2] fix(services/unftp_sbe): add `/` to all dir method --- integrations/unftp-sbe/src/lib.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/integrations/unftp-sbe/src/lib.rs b/integrations/unftp-sbe/src/lib.rs index 415c5bc5e76a..71bbdb35c5f8 100644 --- a/integrations/unftp-sbe/src/lib.rs +++ b/integrations/unftp-sbe/src/lib.rs @@ -133,6 +133,14 @@ fn convert_path(path: &Path) -> storage::Result<&str> { }) } +fn convert_dir_path(path: &Path) -> storage::Result<&str> { + let mut path_str = convert_path(path)?.to_string(); + if !path_str.ends_with('/') { + path_str.push('/'); + } + convert_path(&Path::new(&path_str)) +} + #[async_trait::async_trait] impl StorageBackend for OpendalStorage { type Metadata = OpendalMetadata; @@ -160,7 +168,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 +230,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 +248,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 +256,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, From f02f6d3038823d5b853a0ff5bab7313954e972e2 Mon Sep 17 00:00:00 2001 From: Frank Wang <1454884738@qq.com> Date: Thu, 5 Dec 2024 12:38:10 -0600 Subject: [PATCH 2/2] fix: logic --- integrations/unftp-sbe/src/lib.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/integrations/unftp-sbe/src/lib.rs b/integrations/unftp-sbe/src/lib.rs index 71bbdb35c5f8..43390430afaf 100644 --- a/integrations/unftp-sbe/src/lib.rs +++ b/integrations/unftp-sbe/src/lib.rs @@ -133,12 +133,13 @@ fn convert_path(path: &Path) -> storage::Result<&str> { }) } -fn convert_dir_path(path: &Path) -> storage::Result<&str> { - let mut path_str = convert_path(path)?.to_string(); - if !path_str.ends_with('/') { - path_str.push('/'); +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)) } - convert_path(&Path::new(&path_str)) } #[async_trait::async_trait] @@ -168,7 +169,7 @@ impl StorageBackend for OpendalStorage { { let ret = self .op - .list(convert_dir_path(path.as_ref())?) + .list(&convert_dir_path(path.as_ref())?) .await .map_err(convert_err)? .into_iter() @@ -231,7 +232,7 @@ impl StorageBackend for OpendalStorage { async fn mkd + Send + Debug>(&self, _: &User, path: P) -> storage::Result<()> { self.op - .create_dir(convert_dir_path(path.as_ref())?) + .create_dir(&convert_dir_path(path.as_ref())?) .await .map_err(convert_err) } @@ -248,7 +249,7 @@ impl StorageBackend for OpendalStorage { async fn rmd + Send + Debug>(&self, _: &User, path: P) -> storage::Result<()> { self.op - .remove_all(convert_dir_path(path.as_ref())?) + .remove_all(&convert_dir_path(path.as_ref())?) .await .map_err(convert_err) } @@ -256,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_dir_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,