feat(fs): implement RootNodes trait for Directory
This makes mounting the content of a just ingested archive or directory more straightforward. Change-Id: I64589aad3dc1885c1266310200cdace21e5810e9 Reviewed-on: https://cl.snix.dev/c/snix/+/30292 Reviewed-by: Florian Klink <flokli@flokli.de> Tested-by: besadii
This commit is contained in:
parent
6e45456fec
commit
ad9ef2cd1d
1 changed files with 18 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::nodes::Directory;
|
||||
use crate::{path::PathComponent, Error, Node};
|
||||
use futures::stream::BoxStream;
|
||||
use tonic::async_trait;
|
||||
|
|
@ -37,3 +38,20 @@ where
|
|||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl RootNodes for Directory {
|
||||
async fn get_by_basename(&self, name: &PathComponent) -> Result<Option<Node>, Error> {
|
||||
Ok(self
|
||||
.nodes()
|
||||
.find(|(key, _)| *key == name)
|
||||
.map(|(_, node)| node.clone()))
|
||||
}
|
||||
|
||||
fn list(&self) -> BoxStream<Result<(PathComponent, Node), Error>> {
|
||||
Box::pin(tokio_stream::iter(
|
||||
self.nodes()
|
||||
.map(|(name, node)| Ok((name.to_owned(), node.to_owned()))),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue