about summary refs log tree commit diff
path: root/tvix/nix-compat/src/store_path/mod.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-09-23T09·32+0300
committerflokli <flokli@flokli.de>2023-09-23T12·54+0000
commitdfb3d30d4545015e0cb2c4e7e1e7d43050945262 (patch)
treec7e25dc3e8e4793171ac31c9a0e9c842724782bf /tvix/nix-compat/src/store_path/mod.rs
parent4f13b520470f261be234bd5efa7913118534d0af (diff)
fix(tvix/nix-compat): drop first character period check r/6640
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 <tvl@lahfa.xyz>
Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/nix-compat/src/store_path/mod.rs')
-rw-r--r--tvix/nix-compat/src/store_path/mod.rs16
1 files changed, 10 insertions, 6 deletions
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<String, Error> {
     // Empty names are not allowed.
@@ -161,11 +161,6 @@ pub(crate) fn validate_name(s: &[u8]) -> Result<String, Error> {
         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")