diff options
author | Florian Klink <flokli@flokli.de> | 2024-01-12T13·28+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-01-12T20·38+0000 |
commit | 639ee1910180d8e69787b85d6ab0034ede7e2a07 (patch) | |
tree | 72ebbf2254d13436ae6dbb7903fdad71abb95d03 /tvix | |
parent | b59df53774acc654ea4b23f02ccf5529587bceff (diff) |
refactor(tvix/glue/tvix_store_io): async store_path_to_node r/7372
Provide a store_path_to_node_sync function which uses the runtime handle to block on the async function internally, but make store_path_to_node itself async, so it can call async functions internally. We'll use that later when triggering builds and waiting on their results. Change-Id: Idae9da7aa5b0878e0d3a2eba34ea2623e1ba84b2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10607 Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de> Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Diffstat (limited to 'tvix')
-rw-r--r-- | tvix/glue/src/tvix_store_io.rs | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/tvix/glue/src/tvix_store_io.rs b/tvix/glue/src/tvix_store_io.rs index 178bf6c77788..251023ba3eab 100644 --- a/tvix/glue/src/tvix_store_io.rs +++ b/tvix/glue/src/tvix_store_io.rs @@ -60,20 +60,16 @@ where /// In case there is no PathInfo yet, this means we need to build it /// (which currently is stubbed out still). #[instrument(skip(self), ret, err)] - fn store_path_to_node( + async fn store_path_to_node( &self, store_path: &StorePath, sub_path: &Path, ) -> io::Result<Option<Node>> { let root_node = match self - .tokio_handle - .block_on(async { - self.path_info_service - .as_ref() - .get(*store_path.digest()) - .await - }) - .unwrap() + .path_info_service + .as_ref() + .get(*store_path.digest()) + .await? { // if we have a PathInfo, we know there will be a root_node (due to validation) Some(path_info) => path_info.node.expect("no node").node.expect("no node"), @@ -90,11 +86,18 @@ where }; // with the root_node and sub_path, descend to the node requested. - Ok(self.tokio_handle.block_on({ - async { - directoryservice::descend_to(&self.directory_service, root_node, sub_path).await - } - })?) + directoryservice::descend_to(&self.directory_service, root_node, sub_path) + .await + .map_err(|e| std::io::Error::new(io::ErrorKind::Other, e)) + } + + fn store_path_to_node_sync( + &self, + store_path: &StorePath, + sub_path: &Path, + ) -> io::Result<Option<Node>> { + self.tokio_handle + .block_on(async { self.store_path_to_node(store_path, sub_path).await }) } } @@ -109,7 +112,10 @@ where if let Ok((store_path, sub_path)) = StorePath::from_absolute_path_full(&path.to_string_lossy()) { - if self.store_path_to_node(&store_path, &sub_path)?.is_some() { + if self + .store_path_to_node_sync(&store_path, &sub_path)? + .is_some() + { Ok(true) } else { // As tvix-store doesn't manage /nix/store on the filesystem, @@ -127,7 +133,7 @@ where if let Ok((store_path, sub_path)) = StorePath::from_absolute_path_full(&path.to_string_lossy()) { - if let Some(node) = self.store_path_to_node(&store_path, &sub_path)? { + if let Some(node) = self.store_path_to_node_sync(&store_path, &sub_path)? { // depending on the node type, treat read_to_string differently match node { Node::Directory(_) => { @@ -195,7 +201,7 @@ where if let Ok((store_path, sub_path)) = StorePath::from_absolute_path_full(&path.to_string_lossy()) { - if let Some(node) = self.store_path_to_node(&store_path, &sub_path)? { + if let Some(node) = self.store_path_to_node_sync(&store_path, &sub_path)? { match node { Node::Directory(directory_node) => { // fetch the Directory itself. |