in core/src/raw/oio/page/into_hierarchy_pager.rs [58:116]
fn filter_entries(&mut self, entries: Vec<oio::Entry>) -> Vec<oio::Entry> {
entries
.into_iter()
.filter_map(|mut e| {
// If path is not started with prefix, drop it.
//
// Ideally, it should never happen. But we just tolerate
// this state.
if !e.path().starts_with(&self.path) {
return None;
}
// Dir itself should not be returned in hierarchy page.
if e.path() == self.path {
return None;
}
let prefix_len = self.path.len();
let idx = if let Some(idx) = e.path()[prefix_len..].find('/') {
idx + prefix_len + 1
} else {
// If there is no `/` in path, it's a normal file, we
// can return it directly.
return Some(e);
};
// idx == path.len() means it's contain only one `/` at the
// end of path.
if idx == e.path().len() {
if !self.visited.contains(e.path()) {
self.visited.insert(e.path().to_string());
}
return Some(e);
}
// If idx < path.len() means that are more levels to come.
// We should check the first dir path.
let has = {
let path = &e.path()[..idx];
self.visited.contains(path)
};
if !has {
let path = {
let path = &e.path()[..idx];
path.to_string()
};
e.set_path(&path);
e.set_mode(EntryMode::DIR);
self.visited.insert(path);
return Some(e);
}
None
})
.collect()
}