Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(services/unftp_sbe): add / to path when operate on dir #5395

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions integrations/unftp-sbe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ fn convert_path(path: &Path) -> storage::Result<&str> {
})
}

fn convert_dir_path(path: &Path) -> storage::Result<String> {
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<User: UserDetail> StorageBackend<User> for OpendalStorage {
type Metadata = OpendalMetadata;
Expand Down Expand Up @@ -160,7 +169,7 @@ impl<User: UserDetail> StorageBackend<User> 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()
Expand Down Expand Up @@ -222,11 +231,10 @@ impl<User: UserDetail> StorageBackend<User> for OpendalStorage {
}

async fn mkd<P: AsRef<Path> + 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<P: AsRef<Path> + Send + Debug>(
Expand All @@ -241,15 +249,15 @@ impl<User: UserDetail> StorageBackend<User> for OpendalStorage {

async fn rmd<P: AsRef<Path> + 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)
}

async fn cwd<P: AsRef<Path> + 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,
Expand Down
Loading