From 8d86d2f4094190e141da1d3c8bcb67181edfa211 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 23 Dec 2023 12:24:14 +0200 Subject: refactor(tvix/castore): add RootNode impl for BTreeMap, mv fs tests cl/10378 did already move store/fs to castore/fs, but we kept the tests in tvix-store, as they were populating a PathInfoService to make nodes appear in the mount root. Update these tests to now just insert root nodes into a BTreeMap, and ensure we can use that as a RootNodes too. Change-Id: Iad7d1ee4f9423eb6e3a1da33f433842c9ae0de1f Reviewed-on: https://cl.tvl.fyi/c/depot/+/10410 Reviewed-by: raitobezarius Tested-by: BuildkiteCI Autosubmit: flokli --- tvix/castore/src/fs/root_nodes.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'tvix/castore/src/fs/root_nodes.rs') diff --git a/tvix/castore/src/fs/root_nodes.rs b/tvix/castore/src/fs/root_nodes.rs index 8d27b477ff69..312a0b2cdd7e 100644 --- a/tvix/castore/src/fs/root_nodes.rs +++ b/tvix/castore/src/fs/root_nodes.rs @@ -1,6 +1,7 @@ -use std::pin::Pin; +use std::{collections::BTreeMap, ops::Deref, pin::Pin}; use crate::{proto::node::Node, Error}; +use bytes::Bytes; use futures::Stream; use tonic::async_trait; @@ -14,5 +15,21 @@ pub trait RootNodes: Send + Sync { /// Lists all root CA nodes in the filesystem. An error can be returned /// in case listing is not allowed - fn list(&self) -> Pin> + Send>>; + fn list(&self) -> Pin> + Send + '_>>; +} + +#[async_trait] +/// Implements RootNodes for something deref'ing to a BTreeMap of Nodes, where +/// the key is the node name. +impl RootNodes for T +where + T: Deref> + Send + Sync, +{ + async fn get_by_basename(&self, name: &[u8]) -> Result, Error> { + Ok(self.get(name).cloned()) + } + + fn list(&self) -> Pin> + Send + '_>> { + Box::pin(tokio_stream::iter(self.iter().map(|(_, v)| Ok(v.clone())))) + } } -- cgit 1.4.1