From dfb3d30d4545015e0cb2c4e7e1e7d43050945262 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 23 Sep 2023 12:32:20 +0300 Subject: fix(tvix/nix-compat): drop first character period check Suggested in https://cl.tvl.fyi/c/depot/+/9108/5, but this disallows adding a .gitignore file to the store. Remove the check, and add a testcase. Change-Id: Ieb78c417934756b2dbeb493040fe79726d1b9079 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9447 Tested-by: BuildkiteCI Reviewed-by: raitobezarius Autosubmit: flokli --- tvix/nix-compat/src/store_path/mod.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'tvix') diff --git a/tvix/nix-compat/src/store_path/mod.rs b/tvix/nix-compat/src/store_path/mod.rs index e9e2978b7cc8..b68a4f317189 100644 --- a/tvix/nix-compat/src/store_path/mod.rs +++ b/tvix/nix-compat/src/store_path/mod.rs @@ -153,7 +153,7 @@ impl StorePath { } } -/// Checks a given &[u8] to match the restrictions for store path names, and +/// Checks a given &[u8] to match the restrictions for [StorePath::name], and /// returns the name as string if successful. pub(crate) fn validate_name(s: &[u8]) -> Result { // Empty names are not allowed. @@ -161,11 +161,6 @@ pub(crate) fn validate_name(s: &[u8]) -> Result { return Err(Error::InvalidLength()); } - // First character cannot be a period - if s[0] == b'.' { - return Err(Error::InvalidName(s.to_vec(), 0)); - } - for (i, c) in s.iter().enumerate() { if c.is_ascii_alphanumeric() || *c == b'-' @@ -226,6 +221,15 @@ mod tests { assert_eq!(example_nix_path_str, nixpath.to_string()) } + /// This is the store path produced after `nix-store --add`'ing an + /// empty `.gitignore` file. + #[test] + fn starts_with_dot() { + let nix_path_str = "fli4bwscgna7lpm7v5xgnjxrxh0yc7ra-.gitignore"; + let nixpath = StorePath::from_bytes(nix_path_str.as_bytes()).expect("must succeed"); + assert_eq!(".gitignore", nixpath.name); + } + #[test] fn invalid_hash_length() { StorePath::from_bytes(b"00bgd045z0d4icpbc2yy-net-tools-1.60_p20170221182432") -- cgit 1.4.1