about summary refs log tree commit diff
path: root/tvix/glue/src/tvix_store_io.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2024-08-15T23·24+0300
committerclbot <clbot@tvl.fyi>2024-08-17T09·46+0000
commit8ea7d2b60eb4052d934820078c31ff25786376a4 (patch)
treeda04e2f8f655f31c07a03d13ccbb1e0a7ed8e159 /tvix/glue/src/tvix_store_io.rs
parent49b173786cba575dbeb9d28fa7a62275d45ce41a (diff)
refactor(tvix/castore): drop {Directory,File,Symlink}Node r/8505
Add a `SymlinkTarget` type to represent validated symlink targets.
With this, no invalid states are representable, so we can make `Node` be
just an enum of all three kind of types, and allow access to these
fields directly.

Change-Id: I20bdd480c8d5e64a827649f303c97023b7e390f2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12216
Reviewed-by: benjaminedwardwebb <benjaminedwardwebb@gmail.com>
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/glue/src/tvix_store_io.rs')
-rw-r--r--tvix/glue/src/tvix_store_io.rs41
1 files changed, 18 insertions, 23 deletions
diff --git a/tvix/glue/src/tvix_store_io.rs b/tvix/glue/src/tvix_store_io.rs
index 4185c9554810..234a5ef38f43 100644
--- a/tvix/glue/src/tvix_store_io.rs
+++ b/tvix/glue/src/tvix_store_io.rs
@@ -475,20 +475,16 @@ impl EvalIO for TvixStoreIO {
             {
                 // depending on the node type, treat open differently
                 match node {
-                    Node::Directory(_) => {
+                    Node::Directory { .. } => {
                         // This would normally be a io::ErrorKind::IsADirectory (still unstable)
                         Err(io::Error::new(
                             io::ErrorKind::Unsupported,
                             format!("tried to open directory at {:?}", path),
                         ))
                     }
-                    Node::File(file_node) => {
+                    Node::File { digest, .. } => {
                         self.tokio_handle.block_on(async {
-                            let resp = self
-                                .blob_service
-                                .as_ref()
-                                .open_read(file_node.digest())
-                                .await?;
+                            let resp = self.blob_service.as_ref().open_read(&digest).await?;
                             match resp {
                                 Some(blob_reader) => {
                                     // The VM Response needs a sync [std::io::Reader].
@@ -497,18 +493,18 @@ impl EvalIO for TvixStoreIO {
                                 }
                                 None => {
                                     error!(
-                                        blob.digest = %file_node.digest(),
+                                        blob.digest = %digest,
                                         "blob not found",
                                     );
                                     Err(io::Error::new(
                                         io::ErrorKind::NotFound,
-                                        format!("blob {} not found", &file_node.digest()),
+                                        format!("blob {} not found", &digest),
                                     ))
                                 }
                             }
                         })
                     }
-                    Node::Symlink(_symlink_node) => Err(io::Error::new(
+                    Node::Symlink { .. } => Err(io::Error::new(
                         io::ErrorKind::Unsupported,
                         "open for symlinks is unsupported",
                     ))?,
@@ -534,9 +530,9 @@ impl EvalIO for TvixStoreIO {
                 .block_on(async { self.store_path_to_node(&store_path, &sub_path).await })?
             {
                 match node {
-                    Node::Directory(_) => Ok(FileType::Directory),
-                    Node::File(_) => Ok(FileType::Regular),
-                    Node::Symlink(_) => Ok(FileType::Symlink),
+                    Node::Directory { .. } => Ok(FileType::Directory),
+                    Node::File { .. } => Ok(FileType::Regular),
+                    Node::Symlink { .. } => Ok(FileType::Symlink),
                 }
             } else {
                 self.std_io.file_type(path)
@@ -556,20 +552,19 @@ impl EvalIO for TvixStoreIO {
                 .block_on(async { self.store_path_to_node(&store_path, &sub_path).await })?
             {
                 match node {
-                    Node::Directory(directory_node) => {
+                    Node::Directory { digest, .. } => {
                         // fetch the Directory itself.
-                        let digest = directory_node.digest().clone();
-
-                        if let Some(directory) = self.tokio_handle.block_on(async {
-                            self.directory_service.as_ref().get(&digest).await
+                        if let Some(directory) = self.tokio_handle.block_on({
+                            let digest = digest.clone();
+                            async move { self.directory_service.as_ref().get(&digest).await }
                         })? {
                             let mut children: Vec<(bytes::Bytes, FileType)> = Vec::new();
                             // TODO: into_nodes() to avoid cloning
                             for (name, node) in directory.nodes() {
                                 children.push(match node {
-                                    Node::Directory(_) => (name.clone(), FileType::Directory),
-                                    Node::File(_) => (name.clone(), FileType::Regular),
-                                    Node::Symlink(_) => (name.clone(), FileType::Symlink),
+                                    Node::Directory { .. } => (name.clone(), FileType::Directory),
+                                    Node::File { .. } => (name.clone(), FileType::Regular),
+                                    Node::Symlink { .. } => (name.clone(), FileType::Symlink),
                                 })
                             }
                             Ok(children)
@@ -586,14 +581,14 @@ impl EvalIO for TvixStoreIO {
                             ))?
                         }
                     }
-                    Node::File(_file_node) => {
+                    Node::File { .. } => {
                         // This would normally be a io::ErrorKind::NotADirectory (still unstable)
                         Err(io::Error::new(
                             io::ErrorKind::Unsupported,
                             "tried to readdir path {:?}, which is a file",
                         ))?
                     }
-                    Node::Symlink(_symlink_node) => Err(io::Error::new(
+                    Node::Symlink { .. } => Err(io::Error::new(
                         io::ErrorKind::Unsupported,
                         "read_dir for symlinks is unsupported",
                     ))?,