diff options
author | Florian Klink <flokli@flokli.de> | 2022-12-29T20·32+0100 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2022-12-29T21·55+0000 |
commit | 5ba47a2bc39b95fa4ece5d52ce08bfeda130367f (patch) | |
tree | 37201645e03bd0a60d13066741414d1c7d78d128 /tvix | |
parent | e97a429e73c8bce41a88527fdebce4f1373152a6 (diff) |
feat(tvix/store): parameterise validate_node_name error r/5549
We'll be using validate_node_name in other places in a bit, where returning a ValidateDirectoryError is not appropriate. Accept a function mapping a string to error as a second argument, and pass ValidateDirectoryError::InvalidName at the current call sites. Change-Id: I45cbb0deb4763061ad912c6b18a112c727795a17 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7682 Tested-by: BuildkiteCI Reviewed-by: jrhahn <mail.jhahn@gmail.com> Reviewed-by: tazjin <tazjin@tvl.su> Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix')
-rw-r--r-- | tvix/store/src/proto.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/tvix/store/src/proto.rs b/tvix/store/src/proto.rs index 74563db3fb9a..8a5a10c21233 100644 --- a/tvix/store/src/proto.rs +++ b/tvix/store/src/proto.rs @@ -24,15 +24,14 @@ pub enum ValidateDirectoryError { InvalidDigestLen(usize), } -/// Checks a name for validity. +/// Checks a Node name for validity as an intermediate node, and returns an +/// error that's generated from the supplied constructor. +/// /// We disallow slashes, null bytes, '.', '..' and the empty string. -/// Depending on the context, a [DirectoryNode], [FileNode] or [SymlinkNode] -/// message with an empty string as name is allowed, but they don't occur -/// inside a Directory message. -fn validate_node_name(name: &str) -> Result<(), ValidateDirectoryError> { +fn validate_node_name<E>(name: &str, err: fn(String) -> E) -> Result<(), E> { if name.is_empty() || name == ".." || name == "." || name.contains('\x00') || name.contains('/') { - return Err(ValidateDirectoryError::InvalidName(name.to_string())); + return Err(err(name.to_string())); } Ok(()) } @@ -105,7 +104,7 @@ impl Directory { // check directories for directory_node in &self.directories { - validate_node_name(&directory_node.name)?; + validate_node_name(&directory_node.name, ValidateDirectoryError::InvalidName)?; validate_digest(&directory_node.digest)?; update_if_lt_prev(&mut last_directory_name, directory_node.name.as_str())?; @@ -114,7 +113,7 @@ impl Directory { // check files for file_node in &self.files { - validate_node_name(&file_node.name)?; + validate_node_name(&file_node.name, ValidateDirectoryError::InvalidName)?; validate_digest(&file_node.digest)?; update_if_lt_prev(&mut last_file_name, file_node.name.as_str())?; @@ -123,7 +122,7 @@ impl Directory { // check symlinks for symlink_node in &self.symlinks { - validate_node_name(&symlink_node.name)?; + validate_node_name(&symlink_node.name, ValidateDirectoryError::InvalidName)?; update_if_lt_prev(&mut last_symlink_name, symlink_node.name.as_str())?; insert_once(&mut seen_names, symlink_node.name.as_str())?; |