snix_store/pathinfoservice/fs/
mod.rs1use futures::stream::BoxStream;
2use futures::{StreamExt, TryStreamExt};
3use nix_compat::store_path::StorePathRef;
4use snix_castore::fs::{RootNodes, SnixStoreFs};
5use snix_castore::{Error, Node, PathComponent};
6use snix_castore::{blobservice::BlobService, directoryservice::DirectoryService};
7use tonic::async_trait;
8
9use super::PathInfoService;
10
11pub fn make_fs<BS, DS, PS>(
16 blob_service: BS,
17 directory_service: DS,
18 path_info_service: PS,
19 list_root: bool,
20 show_xattr: bool,
21) -> SnixStoreFs<BS, DS, RootNodesWrapper<PS>>
22where
23 BS: BlobService + Send + Clone + 'static,
24 DS: DirectoryService + Send + Clone + 'static,
25 PS: PathInfoService + Send + Sync + Clone + 'static,
26{
27 SnixStoreFs::new(
28 blob_service,
29 directory_service,
30 RootNodesWrapper(path_info_service),
31 list_root,
32 show_xattr,
33 )
34}
35
36#[doc(hidden)]
39#[derive(Clone, Debug)]
40pub struct RootNodesWrapper<T>(pub(crate) T);
41
42#[cfg(any(feature = "fuse", feature = "virtiofs"))]
46#[async_trait]
47impl<T> RootNodes for RootNodesWrapper<T>
48where
49 T: PathInfoService,
50{
51 async fn get_by_basename(&self, name: &PathComponent) -> Result<Option<Node>, Error> {
52 let Ok(store_path) = StorePathRef::from_bytes(name.as_ref()) else {
53 return Ok(None);
54 };
55
56 Ok(self
57 .0
58 .get(*store_path.digest())
59 .await?
60 .map(|path_info| path_info.node))
61 }
62
63 fn list(&self) -> BoxStream<'static, Result<(PathComponent, Node), Error>> {
64 self.0
65 .list()
66 .map_ok(|path_info| {
67 let name = path_info
68 .store_path
69 .to_string()
70 .as_str()
71 .try_into()
72 .expect("Snix bug: StorePath must be PathComponent");
73 (name, path_info.node)
74 })
75 .boxed()
76 }
77}