about summary refs log tree commit diff
path: root/tvix/eval/src
diff options
context:
space:
mode:
authorAdam Joseph <adam@westernsemico.com>2023-12-12T09·05-0800
committerclbot <clbot@tvl.fyi>2023-12-12T17·21+0000
commit531f0c0c42246027ed4c6c76e37737dc67228544 (patch)
treedd6bfc83d9033130336fe7225c5ef997df8c785d /tvix/eval/src
parent8d4aa2c15c88d6e2912882ebf480d89c172d4e1f (diff)
fix(tvix/eval): baseNameOf should not coerce paths into strings r/7194
... since this may import them to the store which changes their
basename.

Fixes b/350.

Change-Id: Iabd08ff4d6a424c66d6d7784d7a96b0c078f0a91
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10298
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Autosubmit: Adam Joseph <adam@westernsemico.com>
Diffstat (limited to 'tvix/eval/src')
-rw-r--r--tvix/eval/src/builtins/mod.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index 4bdce300a564..181ddeed82e8 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -134,10 +134,18 @@ mod pure_builtins {
     #[builtin("baseNameOf")]
     async fn builtin_base_name_of(co: GenCo, s: Value) -> Result<Value, ErrorKind> {
         let span = generators::request_span(&co).await;
-        let s = s
-            .coerce_to_string(co, CoercionKind::Weak, span)
-            .await?
-            .to_str()?;
+        let s = match s {
+            // it is important that builtins.baseNameOf does not
+            // coerce paths into strings, since this will turn them
+            // into store paths, and `builtins.baseNameOf
+            // ./config.nix` will return a hash-prefixed value like
+            // "hpmyf3vlqg5aadri97xglcvvjbk8xw3g-config.nix"
+            Value::Path(p) => NixString::from(p.to_string_lossy().to_string()),
+            _ => s
+                .coerce_to_string(co, CoercionKind::Weak, span)
+                .await?
+                .to_str()?,
+        };
         let result: String = s.rsplit_once('/').map(|(_, x)| x).unwrap_or(&s).into();
         Ok(result.into())
     }