From ad9ef2cd1d6ac5604ce02c8a73f7cbcd7a80eeaa Mon Sep 17 00:00:00 2001 From: Yvan Sraka Date: Thu, 3 Apr 2025 17:42:34 +0200 Subject: [PATCH] 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 Tested-by: besadii --- snix/castore/src/fs/root_nodes.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/snix/castore/src/fs/root_nodes.rs b/snix/castore/src/fs/root_nodes.rs index 3f75e35f6..016c73c40 100644 --- a/snix/castore/src/fs/root_nodes.rs +++ b/snix/castore/src/fs/root_nodes.rs @@ -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, Error> { + Ok(self + .nodes() + .find(|(key, _)| *key == name) + .map(|(_, node)| node.clone())) + } + + fn list(&self) -> BoxStream> { + Box::pin(tokio_stream::iter( + self.nodes() + .map(|(name, node)| Ok((name.to_owned(), node.to_owned()))), + )) + } +}