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 78a1f66cc5 fix(services/aliyun-drive): unable to list `/` (#4754)
78a1f66cc5 is described below

commit 78a1f66cc596779e78975c5947853a492f4e916b
Author: Hanchin Hsieh <[email protected]>
AuthorDate: Tue Jun 18 14:46:34 2024 +0800

    fix(services/aliyun-drive): unable to list `/` (#4754)
    
    Signed-off-by: Hanchin Hsieh <[email protected]>
---
 core/src/services/aliyun_drive/core.rs | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/core/src/services/aliyun_drive/core.rs 
b/core/src/services/aliyun_drive/core.rs
index 00ac06b926..8e057683b1 100644
--- a/core/src/services/aliyun_drive/core.rs
+++ b/core/src/services/aliyun_drive/core.rs
@@ -170,9 +170,21 @@ impl AliyunDriveCore {
         Ok((token, drive_id.clone()))
     }
 
-    pub async fn get_by_path(&self, path: &str) -> Result<Buffer> {
-        let file_path = build_rooted_abs_path(&self.root, path);
+    pub fn build_path(&self, path: &str, rooted: bool) -> String {
+        let file_path = if rooted {
+            build_rooted_abs_path(&self.root, path)
+        } else {
+            build_abs_path(&self.root, path)
+        };
         let file_path = file_path.strip_suffix('/').unwrap_or(&file_path);
+        if file_path.is_empty() {
+            return "/".to_string();
+        }
+        file_path.to_string()
+    }
+
+    pub async fn get_by_path(&self, path: &str) -> Result<Buffer> {
+        let file_path = self.build_path(path, true);
         let req = Request::post(format!(
             "{}/adrive/v1.0/openFile/get_by_path",
             self.endpoint
@@ -180,7 +192,7 @@ impl AliyunDriveCore {
         let (token, drive_id) = self.get_token_and_drive().await?;
         let body = serde_json::to_vec(&GetByPathRequest {
             drive_id: &drive_id,
-            file_path,
+            file_path: &file_path,
         })
         .map_err(new_json_serialize_error)?;
         let req = req
@@ -190,7 +202,7 @@ impl AliyunDriveCore {
     }
 
     pub async fn ensure_dir_exists(&self, path: &str) -> Result<String> {
-        let file_path = build_abs_path(&self.root, 
path.strip_suffix('/').unwrap_or(path));
+        let file_path = self.build_path(path, false);
         if file_path == "/" {
             return Ok("root".to_string());
         }

Reply via email to