Skip to content

Commit 859b100

Browse files
committed
fix(services/etcd): fill content length from list response
1 parent d2516e2 commit 859b100

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

core/services/etcd/src/lister.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use opendal_core::*;
2626
pub struct EtcdLister {
2727
root: String,
2828
path: String,
29-
iter: IntoIter<String>,
29+
iter: IntoIter<(String, u64)>,
3030
}
3131

3232
impl EtcdLister {
@@ -35,11 +35,7 @@ impl EtcdLister {
3535

3636
// Get all keys with the specified prefix
3737
let mut client = core.conn().await?;
38-
let get_options = Some(
39-
etcd_client::GetOptions::new()
40-
.with_prefix()
41-
.with_keys_only(),
42-
);
38+
let get_options = Some(etcd_client::GetOptions::new().with_prefix());
4339
let resp = client
4440
.get(abs_path.as_str(), get_options)
4541
.await
@@ -52,7 +48,8 @@ impl EtcdLister {
5248
Error::new(ErrorKind::Unexpected, "store key is not valid utf-8 string")
5349
.set_source(err)
5450
})?;
55-
keys.push(key);
51+
let value_len = kv.value().len() as u64;
52+
keys.push((key, value_len));
5653
}
5754

5855
Ok(Self {
@@ -65,11 +62,15 @@ impl EtcdLister {
6562

6663
impl oio::List for EtcdLister {
6764
async fn next(&mut self) -> Result<Option<Entry>> {
68-
for key in self.iter.by_ref() {
65+
for (key, value_len) in self.iter.by_ref() {
6966
if key.starts_with(&self.path) {
7067
let path = build_rel_path(&self.root, &key);
68+
let mut metadata = Metadata::new(EntryMode::from_path(&key));
69+
if metadata.mode().is_file() {
70+
metadata.set_content_length(value_len);
71+
}
7172

72-
let entry = Entry::new(&path, Metadata::new(EntryMode::from_path(&key)));
73+
let entry = Entry::new(&path, metadata);
7374
return Ok(Some(entry));
7475
}
7576
}

0 commit comments

Comments
 (0)