refactor(tvix/store): use bytes for node names and symlink targets

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
This commit is contained in:
Florian Klink 2023-07-18 19:37:25 +03:00 committed by clbot
parent 638f3e874d
commit 72e82ffcb1
27 changed files with 245 additions and 253 deletions

View file

@ -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)]