diff options
author | Florian Klink <flokli@flokli.de> | 2023-07-18T16·37+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-07-21T19·01+0000 |
commit | 72e82ffcb11b1aaf1f1cc8db4189ced5ec0aa42e (patch) | |
tree | fbf51cd1d47df2f3341795fe6bcf8e0a95ccebef /tvix/nix-compat | |
parent | 638f3e874d5eb6c157ffd065e593ee1a8a14d3e0 (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/nix-compat')
-rw-r--r-- | tvix/nix-compat/src/nar/writer/mod.rs | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/tvix/nix-compat/src/nar/writer/mod.rs b/tvix/nix-compat/src/nar/writer/mod.rs index f24b69883876..aafb26c86dba 100644 --- a/tvix/nix-compat/src/nar/writer/mod.rs +++ b/tvix/nix-compat/src/nar/writer/mod.rs @@ -67,21 +67,21 @@ impl<'a, 'w> Node<'a, 'w> { } /// Make this node a symlink. - pub fn symlink(mut self, target: &str) -> io::Result<()> { + pub fn symlink(mut self, target: &[u8]) -> io::Result<()> { debug_assert!( target.len() <= wire::MAX_TARGET_LEN, "target.len() > {}", wire::MAX_TARGET_LEN ); debug_assert!( - !target.contains('\0'), + !target.contains(&b'\0'), "invalid target characters: {target:?}" ); debug_assert!(!target.is_empty(), "empty target"); self.write(&wire::TOK_SYM)?; self.write(&target.len().to_le_bytes())?; - self.write(target.as_bytes())?; + self.write(target)?; self.pad(target.len() as u64)?; self.write(&wire::TOK_PAR)?; Ok(()) @@ -136,11 +136,11 @@ impl<'a, 'w> Node<'a, 'w> { } #[cfg(debug_assertions)] -type Name = String; +type Name = Vec<u8>; #[cfg(not(debug_assertions))] type Name = (); -fn into_name(_name: &str) -> Name { +fn into_name(_name: &[u8]) -> Name { #[cfg(debug_assertions)] _name.to_owned() } @@ -163,17 +163,18 @@ impl<'a, 'w> Directory<'a, 'w> { /// /// The entry is simply another [`Node`], which can then be filled like the /// root of a NAR (including, of course, by nesting directories). - pub fn entry(&mut self, name: &str) -> io::Result<Node<'_, 'w>> { + pub fn entry(&mut self, name: &[u8]) -> io::Result<Node<'_, 'w>> { debug_assert!( name.len() <= wire::MAX_NAME_LEN, "name.len() > {}", wire::MAX_NAME_LEN ); - debug_assert!(!["", ".", ".."].contains(&name), "invalid name: {name:?}"); - debug_assert!( - !name.contains(['/', '\0']), - "invalid name characters: {name:?}" - ); + debug_assert!(name != b"", "name may not be empty"); + debug_assert!(name != b".", "invalid name: {name:?}"); + debug_assert!(name != b"..", "invalid name: {name:?}"); + + debug_assert!(!name.contains(&b'/'), "invalid name characters: {name:?}"); + debug_assert!(!name.contains(&b'\0'), "invalid name characters: {name:?}"); match self.prev_name { None => { @@ -187,7 +188,7 @@ impl<'a, 'w> Directory<'a, 'w> { "misordered names: {_prev_name:?} >= {name:?}" ); _prev_name.clear(); - _prev_name.push_str(name); + _prev_name.append(&mut name.to_vec()); } self.node.write(&wire::TOK_PAR)?; } @@ -195,7 +196,7 @@ impl<'a, 'w> Directory<'a, 'w> { self.node.write(&wire::TOK_ENT)?; self.node.write(&name.len().to_le_bytes())?; - self.node.write(name.as_bytes())?; + self.node.write(name)?; self.node.pad(name.len() as u64)?; self.node.write(&wire::TOK_NOD)?; |