diff options
author | Adam Joseph <adam@westernsemico.com> | 2022-10-13T06·10-0700 |
---|---|---|
committer | Adam Joseph <adam@westernsemico.com> | 2022-10-13T09·48+0000 |
commit | 78d3d9150b1eb76e0820a254c97976e10a8614d6 (patch) | |
tree | c0674d4855f06cb08edbc9709ce2d1abcb455595 /tvix/eval/src | |
parent | 25336fc47b02fe90bf489402ed84f8259aa80ca8 (diff) |
fix(tvix/eval): src/compiler: ensure root_dir is absolute r/5120
Cppnix immediately absolutizes pathnames at parse time; if you write `./foo`, it is immediately converted to `$(pwd)/foo` and manipulated as an absolute path at all times. To avoid having to introduce filesystem access operations in the implementation of otherwise-pure builtins, let's guarantee that the `root_dir` of the VM is always an absolute path. Signed-off-by: Adam Joseph <adam@westernsemico.com> Change-Id: I7cbbae2cba4b2716ff3f5ff7c9ce0ad529358c8a Reviewed-on: https://cl.tvl.fyi/c/depot/+/6995 Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src')
-rw-r--r-- | tvix/eval/src/compiler/mod.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index e4c2c159da40..bf59027c8b4a 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -112,14 +112,21 @@ impl<'observer> Compiler<'observer> { observer: &'observer mut dyn CompilerObserver, ) -> EvalResult<Self> { let mut root_dir = match location { - Some(dir) => Ok(dir), - None => std::env::current_dir().map_err(|e| Error { - kind: ErrorKind::PathResolution(format!( - "could not determine current directory: {}", - e - )), - span: file.span, - }), + Some(dir) if dir.is_absolute() => Ok(dir), + _ => { + let current_dir = std::env::current_dir().map_err(|e| Error { + kind: ErrorKind::PathResolution(format!( + "could not determine current directory: {}", + e + )), + span: file.span, + })?; + if let Some(dir) = location { + Ok(current_dir.join(dir)) + } else { + Ok(current_dir) + } + } }?; // If the path passed from the caller points to a file, the @@ -131,6 +138,7 @@ impl<'observer> Compiler<'observer> { let globals = globals.borrow(); + debug_assert!(root_dir.is_absolute()); Ok(Self { root_dir, file, |