about summary refs log tree commit diff
path: root/tvix/store/src/store_io.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-07-18T16·37+0300
committerclbot <clbot@tvl.fyi>2023-07-21T19·01+0000
commit72e82ffcb11b1aaf1f1cc8db4189ced5ec0aa42e (patch)
treefbf51cd1d47df2f3341795fe6bcf8e0a95ccebef /tvix/store/src/store_io.rs
parent638f3e874d5eb6c157ffd065e593ee1a8a14d3e0 (diff)
refactor(tvix/store): use bytes for node names and symlink targets r/6436
Some paths might use names that are not valid UTF-8. We should be able
to represent them.

We don't actually need to touch the PathInfo structures, as they need to
represent StorePaths, which come with their own harder restrictions,
which can't encode non-UTF8 data.

While this doesn't change any of the wire format of the gRPC messages,
it does however change the interface of tvix_eval::EvalIO - its
read_dir() method does now return a list of Vec<u8>, rather than
SmolStr. Maybe this should be OsString instead?

Change-Id: I821016d9a58ec441ee081b0b9f01c9240723af0b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8974
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/store/src/store_io.rs')
-rw-r--r--tvix/store/src/store_io.rs30
1 files changed, 19 insertions, 11 deletions
diff --git a/tvix/store/src/store_io.rs b/tvix/store/src/store_io.rs
index fcbc5842a3..701b52f667 100644
--- a/tvix/store/src/store_io.rs
+++ b/tvix/store/src/store_io.rs
@@ -7,7 +7,6 @@ use nix_compat::{
     nixhash::{HashAlgo, NixHash, NixHashWithMode},
     store_path::{build_regular_ca_path, StorePath},
 };
-use smol_str::SmolStr;
 use std::{io, path::Path, path::PathBuf, sync::Arc};
 use tracing::{error, instrument, warn};
 use tvix_eval::{EvalIO, FileType, StdIO};
@@ -130,7 +129,7 @@ impl TvixStoreIO {
 
         // assemble a new root_node with a name that is derived from the nar hash.
         let renamed_root_node = {
-            let name = output_path.to_string();
+            let name = output_path.to_string().into_bytes();
 
             match root_node {
                 crate::proto::node::Node::Directory(n) => {
@@ -265,7 +264,7 @@ impl EvalIO for TvixStoreIO {
     }
 
     #[instrument(skip(self), ret, err)]
-    fn read_dir(&self, path: &Path) -> Result<Vec<(SmolStr, FileType)>, io::Error> {
+    fn read_dir(&self, path: &Path) -> Result<Vec<(Vec<u8>, FileType)>, io::Error> {
         if let Ok((store_path, sub_path)) =
             StorePath::from_absolute_path_full(&path.to_string_lossy())
         {
@@ -285,17 +284,17 @@ impl EvalIO for TvixStoreIO {
                             })?;
 
                         if let Some(directory) = self.directory_service.get(&digest)? {
-                            let mut children: Vec<(SmolStr, FileType)> = Vec::new();
+                            let mut children: Vec<(Vec<u8>, FileType)> = Vec::new();
                             for node in directory.nodes() {
                                 children.push(match node {
                                     crate::proto::node::Node::Directory(e) => {
-                                        (e.name.into(), FileType::Directory)
+                                        (e.name, FileType::Directory)
                                     }
                                     crate::proto::node::Node::File(e) => {
-                                        (e.name.into(), FileType::Regular)
+                                        (e.name, FileType::Regular)
                                     }
                                     crate::proto::node::Node::Symlink(e) => {
-                                        (e.name.into(), FileType::Symlink)
+                                        (e.name, FileType::Symlink)
                                     }
                                 })
                             }
@@ -338,11 +337,20 @@ impl EvalIO for TvixStoreIO {
         let path_info = self.import_path_with_pathinfo(path)?;
 
         // from the [PathInfo], extract the store path (as string).
-        let mut path = PathBuf::from(nix_compat::store_path::STORE_DIR_WITH_SLASH);
-        path.push(path_info.node.unwrap().node.unwrap().get_name());
+        Ok({
+            let mut path = PathBuf::from(nix_compat::store_path::STORE_DIR_WITH_SLASH);
 
-        // and return it
-        Ok(path)
+            let root_node_name = path_info.node.unwrap().node.unwrap().get_name().to_vec();
+
+            // This must be a string, otherwise it would have failed validation.
+            let root_node_name = String::from_utf8(root_node_name).unwrap();
+
+            // append to the PathBuf
+            path.push(root_node_name);
+
+            // and return it
+            path
+        })
     }
 
     #[instrument(skip(self), ret)]