diff options
Diffstat (limited to 'tvix/store/src/pathinfoservice/fs')
-rw-r--r-- | tvix/store/src/pathinfoservice/fs/mod.rs | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/tvix/store/src/pathinfoservice/fs/mod.rs b/tvix/store/src/pathinfoservice/fs/mod.rs index aa64b1c01f16..1f7fa8a8afce 100644 --- a/tvix/store/src/pathinfoservice/fs/mod.rs +++ b/tvix/store/src/pathinfoservice/fs/mod.rs @@ -1,10 +1,10 @@ use futures::stream::BoxStream; use futures::StreamExt; +use nix_compat::store_path::StorePathRef; use tonic::async_trait; use tvix_castore::fs::{RootNodes, TvixStoreFs}; -use tvix_castore::proto as castorepb; -use tvix_castore::Error; use tvix_castore::{blobservice::BlobService, directoryservice::DirectoryService}; +use tvix_castore::{Error, Node, PathComponent}; use super::PathInfoService; @@ -48,8 +48,8 @@ impl<T> RootNodes for RootNodesWrapper<T> where T: AsRef<dyn PathInfoService> + Send + Sync, { - async fn get_by_basename(&self, name: &[u8]) -> Result<Option<castorepb::node::Node>, Error> { - let Ok(store_path) = nix_compat::store_path::StorePath::from_bytes(name) else { + async fn get_by_basename(&self, name: &PathComponent) -> Result<Option<Node>, Error> { + let Ok(store_path) = StorePathRef::from_bytes(name.as_ref()) else { return Ok(None); }; @@ -59,22 +59,31 @@ where .get(*store_path.digest()) .await? .map(|path_info| { - path_info + let node = path_info .node + .as_ref() .expect("missing root node") - .node - .expect("empty node") - })) + .to_owned(); + + match node.into_name_and_node() { + Ok((_name, node)) => Ok(node), + Err(e) => Err(Error::StorageError(e.to_string())), + } + }) + .transpose()?) } - fn list(&self) -> BoxStream<Result<castorepb::node::Node, Error>> { + fn list(&self) -> BoxStream<Result<(PathComponent, Node), Error>> { Box::pin(self.0.as_ref().list().map(|result| { - result.map(|path_info| { - path_info + result.and_then(|path_info| { + let node = path_info .node + .as_ref() .expect("missing root node") - .node - .expect("empty node") + .to_owned(); + + node.into_name_and_node() + .map_err(|e| Error::StorageError(e.to_string())) }) })) } |