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/08/26 15:26:42 UTC
(opendal) branch fix-list created (now da2581379f)
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a change to branch fix-list
in repository https://gitbox.apache.org/repos/asf/opendal.git
at da2581379f fix(core): Fix failed list related tests
This branch includes the following new commits:
new da2581379f fix(core): Fix failed list related tests
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(opendal) 01/01: fix(core): Fix failed list related tests
Posted by xu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch fix-list
in repository https://gitbox.apache.org/repos/asf/opendal.git
commit da2581379f00bd9c06acd4bf8fb4d56b445350a8
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Mon Aug 26 23:26:19 2024 +0800
fix(core): Fix failed list related tests
Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
core/src/raw/oio/entry.rs | 7 ++++++-
core/src/services/azdls/lister.rs | 9 ++++++++-
core/src/services/azfile/lister.rs | 7 +++++++
core/src/services/b2/lister.rs | 10 +++++++---
core/src/services/cos/lister.rs | 7 +++----
core/src/services/gdrive/lister.rs | 7 +++++++
core/src/services/sqlite/backend.rs | 5 ++---
7 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/core/src/raw/oio/entry.rs b/core/src/raw/oio/entry.rs
index 43c4b96311..70320300b0 100644
--- a/core/src/raw/oio/entry.rs
+++ b/core/src/raw/oio/entry.rs
@@ -38,7 +38,12 @@ impl Entry {
}
/// Create a new entry with given value.
- pub fn with(path: String, meta: Metadata) -> Entry {
+ pub fn with(mut path: String, meta: Metadata) -> Entry {
+ // Normalize path as `/` if it's empty.
+ if path.is_empty() {
+ path = "/".to_string();
+ }
+
debug_assert!(
meta.mode().is_dir() == path.ends_with('/'),
"mode {:?} not match with path {}",
diff --git a/core/src/services/azdls/lister.rs b/core/src/services/azdls/lister.rs
index 27d51e2667..a14597961c 100644
--- a/core/src/services/azdls/lister.rs
+++ b/core/src/services/azdls/lister.rs
@@ -56,6 +56,13 @@ impl oio::PageList for AzdlsLister {
return Err(parse_error(resp).await?);
}
+ // Return self at the first page.
+ if ctx.token.is_empty() && !ctx.done {
+ let path = build_rel_path(&self.core.root, &self.path);
+ let e = oio::Entry::new(&path, Metadata::new(EntryMode::DIR));
+ ctx.entries.push_back(e);
+ }
+
// Check whether this list is done.
if let Some(value) = resp.headers().get("x-ms-continuation") {
let value = value.to_str().map_err(|err| {
@@ -90,7 +97,7 @@ impl oio::PageList for AzdlsLister {
.with_last_modified(parse_datetime_from_rfc2822(&object.last_modified)?);
let mut path = build_rel_path(&self.core.root, &object.name);
- if mode == EntryMode::DIR {
+ if path.is_empty() {
path += "/"
};
diff --git a/core/src/services/azfile/lister.rs b/core/src/services/azfile/lister.rs
index 913af07d83..4378c4328d 100644
--- a/core/src/services/azfile/lister.rs
+++ b/core/src/services/azfile/lister.rs
@@ -56,6 +56,13 @@ impl oio::PageList for AzfileLister {
return Err(parse_error(resp).await?);
}
+ // Return self at the first page.
+ if ctx.token.is_empty() && !ctx.done {
+ let path = build_rel_path(&self.core.root, &self.path);
+ let e = oio::Entry::new(&path, Metadata::new(EntryMode::DIR));
+ ctx.entries.push_back(e);
+ }
+
let bs = resp.into_body();
let results: EnumerationResults =
diff --git a/core/src/services/b2/lister.rs b/core/src/services/b2/lister.rs
index 9b27b121c1..e1a0c909e5 100644
--- a/core/src/services/b2/lister.rs
+++ b/core/src/services/b2/lister.rs
@@ -79,6 +79,13 @@ impl oio::PageList for B2Lister {
return Err(parse_error(resp).await?);
}
+ // Return self at the first page.
+ if ctx.token.is_empty() && !ctx.done {
+ let path = build_rel_path(&self.core.root, &self.path);
+ let e = oio::Entry::new(&path, Metadata::new(EntryMode::DIR));
+ ctx.entries.push_back(e);
+ }
+
let bs = resp.into_body();
let output: ListFileNamesResponse =
@@ -96,9 +103,6 @@ impl oio::PageList for B2Lister {
continue;
}
}
- if file.file_name == build_abs_path(&self.core.root, &self.path) {
- continue;
- }
let file_name = file.file_name.clone();
let metadata = parse_file_info(&file);
diff --git a/core/src/services/cos/lister.rs b/core/src/services/cos/lister.rs
index 7022aa9def..b5b66596fa 100644
--- a/core/src/services/cos/lister.rs
+++ b/core/src/services/cos/lister.rs
@@ -81,10 +81,9 @@ impl oio::PageList for CosLister {
}
for object in output.contents {
- let path = build_rel_path(&self.core.root, &object.key);
-
- if path == self.path || path.is_empty() {
- continue;
+ let mut path = build_rel_path(&self.core.root, &object.key);
+ if path.is_empty() {
+ path = "/".to_string();
}
let meta = Metadata::new(EntryMode::from_path(&path)).with_content_length(object.size);
diff --git a/core/src/services/gdrive/lister.rs b/core/src/services/gdrive/lister.rs
index e77a5022da..108df8b42a 100644
--- a/core/src/services/gdrive/lister.rs
+++ b/core/src/services/gdrive/lister.rs
@@ -64,6 +64,13 @@ impl oio::PageList for GdriveLister {
return Ok(());
}
+ // Return self at the first page.
+ if ctx.token.is_empty() && !ctx.done {
+ let path = build_rel_path(&self.core.root, &self.path);
+ let e = oio::Entry::new(&path, Metadata::new(EntryMode::DIR));
+ ctx.entries.push_back(e);
+ }
+
let decoded_response =
serde_json::from_slice::<GdriveFileList>(&bytes).map_err(new_json_deserialize_error)?;
diff --git a/core/src/services/sqlite/backend.rs b/core/src/services/sqlite/backend.rs
index a8f182a901..f353292ad7 100644
--- a/core/src/services/sqlite/backend.rs
+++ b/core/src/services/sqlite/backend.rs
@@ -251,11 +251,10 @@ impl kv::Adapter for Adapter {
let pool = self.get_client().await?;
let value = sqlx::query_scalar(&format!(
- "SELECT `{}` FROM `{}` WHERE `{}` LIKE $1 and `{}` <> $2",
- self.key_field, self.table, self.key_field, self.key_field
+ "SELECT `{}` FROM `{}` WHERE `{}` LIKE $1",
+ self.key_field, self.table, self.key_field
))
.bind(format!("{path}%"))
- .bind(path)
.fetch_all(pool)
.await
.map_err(parse_sqlite_error)?;