You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2024/06/19 04:23:57 UTC
(opendal) branch main updated: fix(services/aliyun-drive): list dir without trailing slash (#4766)
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 c8d33a4604 fix(services/aliyun-drive): list dir without trailing slash (#4766)
c8d33a4604 is described below
commit c8d33a4604ab435b0af41bfad16fd7d7bc01a05b
Author: Hanchin Hsieh <me...@yuchanns.xyz>
AuthorDate: Wed Jun 19 12:23:53 2024 +0800
fix(services/aliyun-drive): list dir without trailing slash (#4766)
---
core/src/services/aliyun_drive/backend.rs | 6 +++--
core/src/services/aliyun_drive/lister.rs | 37 +++++++++++++++++++++++--------
2 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/core/src/services/aliyun_drive/backend.rs b/core/src/services/aliyun_drive/backend.rs
index 9974757bca..2383e5ebfa 100644
--- a/core/src/services/aliyun_drive/backend.rs
+++ b/core/src/services/aliyun_drive/backend.rs
@@ -445,8 +445,10 @@ impl Access for AliyunDriveBackend {
let file: AliyunDriveFile =
serde_json::from_reader(res.reader()).map_err(new_json_serialize_error)?;
Some(AliyunDriveParent {
- parent_path: path.to_string(),
- parent_file_id: file.file_id,
+ file_id: file.file_id,
+ name: file.name,
+ path: path.to_string(),
+ updated_at: file.updated_at,
})
}
};
diff --git a/core/src/services/aliyun_drive/lister.rs b/core/src/services/aliyun_drive/lister.rs
index d3ec4ba886..536da838a0 100644
--- a/core/src/services/aliyun_drive/lister.rs
+++ b/core/src/services/aliyun_drive/lister.rs
@@ -38,8 +38,10 @@ pub struct AliyunDriveLister {
}
pub struct AliyunDriveParent {
- pub parent_path: String,
- pub parent_file_id: String,
+ pub file_id: String,
+ pub name: String,
+ pub path: String,
+ pub updated_at: String,
}
impl AliyunDriveLister {
@@ -64,15 +66,32 @@ impl oio::PageList for AliyunDriveLister {
};
let offset = if ctx.token.is_empty() {
+ if !parent.path.ends_with('/') {
+ // List "dir" should contains "dir/".
+ let path = if !parent.path.starts_with('/') {
+ format!("/{}", parent.path)
+ } else {
+ parent.path.clone()
+ };
+ ctx.entries.push_back(Entry::new(
+ &format!("{}/", path),
+ Metadata::new(EntryMode::DIR).with_last_modified(
+ parent
+ .updated_at
+ .parse::<chrono::DateTime<Utc>>()
+ .map_err(|e| {
+ Error::new(ErrorKind::Unexpected, "parse last modified time")
+ .set_source(e)
+ })?,
+ ),
+ ));
+ }
None
} else {
Some(ctx.token.clone())
};
- let res = self
- .core
- .list(&parent.parent_file_id, self.limit, offset)
- .await;
+ let res = self.core.list(&parent.file_id, self.limit, offset).await;
let res = match res {
Err(err) if err.kind() == ErrorKind::NotFound => {
ctx.done = true;
@@ -92,10 +111,10 @@ impl oio::PageList for AliyunDriveLister {
let n = result.items.len();
for item in result.items {
- let path = if parent.parent_path.starts_with('/') {
- build_abs_path(&parent.parent_path, &item.name)
+ let path = if parent.path.starts_with('/') {
+ build_abs_path(&parent.path, &item.name)
} else {
- build_abs_path(&format!("/{}", &parent.parent_path), &item.name)
+ build_abs_path(&format!("/{}", &parent.path), &item.name)
};
let (path, md) = if item.path_type == "folder" {