From 531f0c0c42246027ed4c6c76e37737dc67228544 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 12 Dec 2023 01:05:02 -0800 Subject: fix(tvix/eval): baseNameOf should not coerce paths into strings ... 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 Tested-by: BuildkiteCI Autosubmit: Adam Joseph --- tvix/eval/src/builtins/mod.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'tvix') 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 { 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()) } -- cgit 1.4.1