about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2024-01-09T09·14+0200
committerclbot <clbot@tvl.fyi>2024-01-09T14·15+0000
commit0009383c073169c5475168a3088452b80e0b8060 (patch)
tree70ee56faa15f38624c51fa0e04df96a014161d72 /tvix
parentb1c556b7e190035e63d7ddf142b7517c2425f806 (diff)
refactor(tvix/castore/directorysvc): AsRef traverse_to r/7361
Change-Id: I641bd4ab3de591a013f03137f1e16295946315f3
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10579
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r--tvix/castore/src/directoryservice/traverse.rs26
-rw-r--r--tvix/glue/src/tvix_store_io.rs3
2 files changed, 13 insertions, 16 deletions
diff --git a/tvix/castore/src/directoryservice/traverse.rs b/tvix/castore/src/directoryservice/traverse.rs
index 1d1de6e18faa..528cef757432 100644
--- a/tvix/castore/src/directoryservice/traverse.rs
+++ b/tvix/castore/src/directoryservice/traverse.rs
@@ -1,6 +1,6 @@
 use super::DirectoryService;
 use crate::{proto::NamedNode, B3Digest, Error};
-use std::{ops::Deref, os::unix::ffi::OsStrExt};
+use std::os::unix::ffi::OsStrExt;
 use tracing::{instrument, warn};
 
 /// This descends from a (root) node to the given (sub)path, returning the Node
@@ -12,7 +12,7 @@ pub async fn descend_to<DS>(
     path: &std::path::Path,
 ) -> Result<Option<crate::proto::node::Node>, Error>
 where
-    DS: Deref<Target = dyn DirectoryService>,
+    DS: AsRef<dyn DirectoryService>,
 {
     // strip a possible `/` prefix from the path.
     let path = {
@@ -45,7 +45,7 @@ where
                         })?;
 
                         // fetch the linked node from the directory_service
-                        match directory_service.get(&digest).await? {
+                        match directory_service.as_ref().get(&digest).await? {
                             // If we didn't get the directory node that's linked, that's a store inconsistency, bail out!
                             None => {
                                 warn!("directory {} does not exist", digest);
@@ -86,9 +86,7 @@ where
 #[cfg(test)]
 mod tests {
     use std::path::PathBuf;
-    use std::sync::Arc;
 
-    use crate::directoryservice::DirectoryService;
     use crate::fixtures::{DIRECTORY_COMPLICATED, DIRECTORY_WITH_KEEP};
     use crate::utils::gen_directory_service;
 
@@ -96,7 +94,7 @@ mod tests {
 
     #[tokio::test]
     async fn test_descend_to() {
-        let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
+        let directory_service = gen_directory_service();
 
         let mut handle = directory_service.put_multiple_start();
         handle
@@ -128,7 +126,7 @@ mod tests {
         // traversal to an empty subpath should return the root node.
         {
             let resp = descend_to(
-                directory_service.clone(),
+                &directory_service,
                 node_directory_complicated.clone(),
                 &PathBuf::from(""),
             )
@@ -141,7 +139,7 @@ mod tests {
         // traversal to `keep` should return the node for DIRECTORY_WITH_KEEP
         {
             let resp = descend_to(
-                directory_service.clone(),
+                &directory_service,
                 node_directory_complicated.clone(),
                 &PathBuf::from("keep"),
             )
@@ -154,7 +152,7 @@ mod tests {
         // traversal to `keep/.keep` should return the node for the .keep file
         {
             let resp = descend_to(
-                directory_service.clone(),
+                &directory_service,
                 node_directory_complicated.clone(),
                 &PathBuf::from("keep/.keep"),
             )
@@ -167,7 +165,7 @@ mod tests {
         // traversal to `keep/.keep` should return the node for the .keep file
         {
             let resp = descend_to(
-                directory_service.clone(),
+                &directory_service,
                 node_directory_complicated.clone(),
                 &PathBuf::from("/keep/.keep"),
             )
@@ -180,7 +178,7 @@ mod tests {
         // traversal to `void` should return None (doesn't exist)
         {
             let resp = descend_to(
-                directory_service.clone(),
+                &directory_service,
                 node_directory_complicated.clone(),
                 &PathBuf::from("void"),
             )
@@ -193,7 +191,7 @@ mod tests {
         // traversal to `void` should return None (doesn't exist)
         {
             let resp = descend_to(
-                directory_service.clone(),
+                &directory_service,
                 node_directory_complicated.clone(),
                 &PathBuf::from("//v/oid"),
             )
@@ -207,7 +205,7 @@ mod tests {
         // reached, as keep/.keep already is a file)
         {
             let resp = descend_to(
-                directory_service.clone(),
+                &directory_service,
                 node_directory_complicated.clone(),
                 &PathBuf::from("keep/.keep/foo"),
             )
@@ -220,7 +218,7 @@ mod tests {
         // traversal to a subpath of '/' should return the root node.
         {
             let resp = descend_to(
-                directory_service.clone(),
+                &directory_service,
                 node_directory_complicated.clone(),
                 &PathBuf::from("/"),
             )
diff --git a/tvix/glue/src/tvix_store_io.rs b/tvix/glue/src/tvix_store_io.rs
index 56e3feb674f3..178bf6c77788 100644
--- a/tvix/glue/src/tvix_store_io.rs
+++ b/tvix/glue/src/tvix_store_io.rs
@@ -92,8 +92,7 @@ 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.as_ref(), root_node, sub_path)
-                    .await
+                directoryservice::descend_to(&self.directory_service, root_node, sub_path).await
             }
         })?)
     }