From d51df2e347ffe87d6a17bbb4d2cf7e08e0368899 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Tue, 27 Aug 2024 01:22:52 +0800 Subject: [PATCH] Fix aliyun drive Signed-off-by: Xuanwo --- core/src/services/aliyun_drive/lister.rs | 56 ++++++++---------------- 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/core/src/services/aliyun_drive/lister.rs b/core/src/services/aliyun_drive/lister.rs index d5de627d111b..4a28e1460023 100644 --- a/core/src/services/aliyun_drive/lister.rs +++ b/core/src/services/aliyun_drive/lister.rs @@ -100,53 +100,35 @@ impl oio::PageList for AliyunDriveLister { let result: AliyunDriveFileList = serde_json::from_reader(res.reader()).map_err(new_json_serialize_error)?; - let n = result.items.len(); - for item in result.items { - let path = build_abs_path(&parent.path, &item.name); - - let (path, md) = if item.path_type == "folder" { - let path = format!("{}/", path); - let meta = Metadata::new(EntryMode::DIR).with_last_modified( - item.updated_at - .parse::>() - .map_err(|e| { - Error::new(ErrorKind::Unexpected, "parse last modified time") - .set_source(e) - })?, - ); - (path, meta) + let (path, mut md) = if item.path_type == "folder" { + let path = format!("{}{}/", &parent.path.trim_start_matches('/'), &item.name); + (path, Metadata::new(EntryMode::DIR)) } else { - let mut meta = Metadata::new(EntryMode::FILE).with_last_modified( - item.updated_at - .parse::>() - .map_err(|e| { - Error::new(ErrorKind::Unexpected, "parse last modified time") - .set_source(e) - })?, - ); - if let Some(v) = item.size { - meta = meta.with_content_length(v); - } - if let Some(v) = item.content_type { - meta = meta.with_content_type(v); - } - (path, meta) + let path = format!("{}{}", &parent.path.trim_start_matches('/'), &item.name); + (path, Metadata::new(EntryMode::FILE)) }; + md = md.with_last_modified(item.updated_at.parse::>().map_err( + |e| Error::new(ErrorKind::Unexpected, "parse last modified time").set_source(e), + )?); + if let Some(v) = item.size { + md = md.with_content_length(v); + } + if let Some(v) = item.content_type { + md = md.with_content_type(v); + } + ctx.entries.push_back(Entry::new(&path, md)); } - if self.limit.is_some_and(|x| x < n) || result.next_marker.is_none() { + let next_marker = result.next_marker.unwrap_or_default(); + if next_marker.is_empty() { ctx.done = true; + } else { + ctx.token = next_marker; } - if let Some(marker) = result.next_marker { - if marker.is_empty() { - ctx.done = true; - } - ctx.token = marker; - } Ok(()) } }