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/aliyun-drive): list dir without trailing slash #4766

Merged
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions core/src/services/aliyun_drive/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
};
Expand Down
37 changes: 28 additions & 9 deletions core/src/services/aliyun_drive/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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" {
Expand Down
Loading