feat(tvix/castore): carry name in ValidateNodeError::InvalidName
Change-Id: Ica288e94f3f6025d98ef7d56dc5d6f874ec921b7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9861 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
parent
e525272019
commit
621739037f
2 changed files with 14 additions and 14 deletions
|
@ -1,7 +1,7 @@
|
||||||
#![allow(clippy::derive_partial_eq_without_eq, non_snake_case)]
|
#![allow(clippy::derive_partial_eq_without_eq, non_snake_case)]
|
||||||
// https://github.com/hyperium/tonic/issues/1056
|
// https://github.com/hyperium/tonic/issues/1056
|
||||||
use bstr::ByteSlice;
|
use bstr::ByteSlice;
|
||||||
use std::{collections::HashSet, iter::Peekable};
|
use std::{collections::HashSet, iter::Peekable, str};
|
||||||
|
|
||||||
use prost::Message;
|
use prost::Message;
|
||||||
|
|
||||||
|
@ -47,8 +47,8 @@ pub enum ValidateNodeError {
|
||||||
#[error("Invalid Digest length: {0}")]
|
#[error("Invalid Digest length: {0}")]
|
||||||
InvalidDigestLen(usize),
|
InvalidDigestLen(usize),
|
||||||
/// Invalid name encountered
|
/// Invalid name encountered
|
||||||
#[error("Invalid name")]
|
#[error("Invalid name: {}", .0.as_bstr())]
|
||||||
InvalidName,
|
InvalidName(Vec<u8>),
|
||||||
/// Invalid symlink target
|
/// Invalid symlink target
|
||||||
#[error("Invalid symlink target: {}", .0.as_bstr())]
|
#[error("Invalid symlink target: {}", .0.as_bstr())]
|
||||||
InvalidSymlinkTarget(Vec<u8>),
|
InvalidSymlinkTarget(Vec<u8>),
|
||||||
|
@ -63,9 +63,10 @@ fn validate_node_name(name: &[u8]) -> Result<(), ValidateNodeError> {
|
||||||
|| name.contains(&0x00)
|
|| name.contains(&0x00)
|
||||||
|| name.contains(&b'/')
|
|| name.contains(&b'/')
|
||||||
{
|
{
|
||||||
Err(ValidateNodeError::InvalidName)?;
|
Err(ValidateNodeError::InvalidName(name.to_owned()))
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// NamedNode is implemented for [FileNode], [DirectoryNode] and [SymlinkNode]
|
/// NamedNode is implemented for [FileNode], [DirectoryNode] and [SymlinkNode]
|
||||||
|
@ -122,14 +123,14 @@ impl node::Node {
|
||||||
directory_node.digest.len(),
|
directory_node.digest.len(),
|
||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
validate_node_name(&directory_node.name)?;
|
validate_node_name(&directory_node.name)
|
||||||
}
|
}
|
||||||
// for a file root node, ensure the digest has the appropriate size.
|
// for a file root node, ensure the digest has the appropriate size.
|
||||||
node::Node::File(file_node) => {
|
node::Node::File(file_node) => {
|
||||||
if file_node.digest.len() != B3_LEN {
|
if file_node.digest.len() != B3_LEN {
|
||||||
Err(ValidateNodeError::InvalidDigestLen(file_node.digest.len()))?;
|
Err(ValidateNodeError::InvalidDigestLen(file_node.digest.len()))?;
|
||||||
}
|
}
|
||||||
validate_node_name(&file_node.name)?;
|
validate_node_name(&file_node.name)
|
||||||
}
|
}
|
||||||
// ensure the symlink target is not empty and doesn't contain null bytes.
|
// ensure the symlink target is not empty and doesn't contain null bytes.
|
||||||
node::Node::Symlink(symlink_node) => {
|
node::Node::Symlink(symlink_node) => {
|
||||||
|
@ -138,10 +139,9 @@ impl node::Node {
|
||||||
symlink_node.target.to_vec(),
|
symlink_node.target.to_vec(),
|
||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
validate_node_name(&symlink_node.name)?;
|
validate_node_name(&symlink_node.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ fn validate_invalid_names() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
match d.validate().expect_err("must fail") {
|
match d.validate().expect_err("must fail") {
|
||||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
|
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName(_)) => {
|
||||||
assert_eq!(n, b"")
|
assert_eq!(n, b"")
|
||||||
}
|
}
|
||||||
_ => panic!("unexpected error"),
|
_ => panic!("unexpected error"),
|
||||||
|
@ -182,7 +182,7 @@ fn validate_invalid_names() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
match d.validate().expect_err("must fail") {
|
match d.validate().expect_err("must fail") {
|
||||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
|
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName(_)) => {
|
||||||
assert_eq!(n, b".")
|
assert_eq!(n, b".")
|
||||||
}
|
}
|
||||||
_ => panic!("unexpected error"),
|
_ => panic!("unexpected error"),
|
||||||
|
@ -200,7 +200,7 @@ fn validate_invalid_names() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
match d.validate().expect_err("must fail") {
|
match d.validate().expect_err("must fail") {
|
||||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
|
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName(_)) => {
|
||||||
assert_eq!(n, b"..")
|
assert_eq!(n, b"..")
|
||||||
}
|
}
|
||||||
_ => panic!("unexpected error"),
|
_ => panic!("unexpected error"),
|
||||||
|
@ -216,7 +216,7 @@ fn validate_invalid_names() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
match d.validate().expect_err("must fail") {
|
match d.validate().expect_err("must fail") {
|
||||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
|
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName(_)) => {
|
||||||
assert_eq!(n, b"\x00")
|
assert_eq!(n, b"\x00")
|
||||||
}
|
}
|
||||||
_ => panic!("unexpected error"),
|
_ => panic!("unexpected error"),
|
||||||
|
@ -232,7 +232,7 @@ fn validate_invalid_names() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
match d.validate().expect_err("must fail") {
|
match d.validate().expect_err("must fail") {
|
||||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
|
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName(_)) => {
|
||||||
assert_eq!(n, b"foo/bar")
|
assert_eq!(n, b"foo/bar")
|
||||||
}
|
}
|
||||||
_ => panic!("unexpected error"),
|
_ => panic!("unexpected error"),
|
||||||
|
|
Loading…
Reference in a new issue