in core/src/raw/oio/list/hierarchy_list.rs [63:116]
fn keep_entry(&mut self, e: &mut oio::Entry) -> bool {
// 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 false;
}
// Don't return already visited path.
if self.visited.contains(e.path()) {
return false;
}
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 true;
};
// 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 true;
}
// 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 true;
}
false
}