opendal/services/hdfs/
lister.rs1use crate::raw::*;
19use crate::EntryMode;
20use crate::Metadata;
21use crate::Result;
22
23pub struct HdfsLister {
24 root: String,
25
26 rd: hdrs::Readdir,
27
28 current_path: Option<String>,
29}
30
31impl HdfsLister {
32 pub fn new(root: &str, rd: hdrs::Readdir, path: &str) -> Self {
33 Self {
34 root: root.to_string(),
35
36 rd,
37
38 current_path: Some(path.to_string()),
39 }
40 }
41}
42
43impl oio::List for HdfsLister {
44 async fn next(&mut self) -> Result<Option<oio::Entry>> {
45 if let Some(path) = self.current_path.take() {
46 return Ok(Some(oio::Entry::new(&path, Metadata::new(EntryMode::DIR))));
47 }
48
49 let de = match self.rd.next() {
50 Some(de) => de,
51 None => return Ok(None),
52 };
53
54 let path = build_rel_path(&self.root, de.path());
55
56 let entry = if de.is_file() {
57 let meta = Metadata::new(EntryMode::FILE)
58 .with_content_length(de.len())
59 .with_last_modified(de.modified().into());
60 oio::Entry::new(&path, meta)
61 } else if de.is_dir() {
62 oio::Entry::new(&format!("{path}/"), Metadata::new(EntryMode::DIR))
64 } else {
65 oio::Entry::new(&path, Metadata::new(EntryMode::Unknown))
66 };
67
68 Ok(Some(entry))
69 }
70}
71
72impl oio::BlockingList for HdfsLister {
73 fn next(&mut self) -> Result<Option<oio::Entry>> {
74 if let Some(path) = self.current_path.take() {
75 return Ok(Some(oio::Entry::new(&path, Metadata::new(EntryMode::DIR))));
76 }
77
78 let de = match self.rd.next() {
79 Some(de) => de,
80 None => return Ok(None),
81 };
82
83 let path = build_rel_path(&self.root, de.path());
84
85 let entry = if de.is_file() {
86 let meta = Metadata::new(EntryMode::FILE)
87 .with_content_length(de.len())
88 .with_last_modified(de.modified().into());
89 oio::Entry::new(&path, meta)
90 } else if de.is_dir() {
91 oio::Entry::new(&format!("{path}/"), Metadata::new(EntryMode::DIR))
93 } else {
94 oio::Entry::new(&path, Metadata::new(EntryMode::Unknown))
95 };
96
97 Ok(Some(entry))
98 }
99}