From 0bf83f08a4099d90ac18f921b45f74124bcb4c62 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Thu, 31 Oct 2024 11:10:05 +1300 Subject: Canonicalize program paths before loading a program In the case that a program with an adjacent symbols file is added to a system-wide programs folder by symbolically linking to the bytecode file of the program, and the program is run via the symbolic link, the symbols file in the original directory will not be found or loaded. To fix this, the path to the symbolic link will now be resolved to the path of the bytecode file in the original directory, where the symbols file can be found. --- src/bin/br.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/bin/br.rs') diff --git a/src/bin/br.rs b/src/bin/br.rs index f2be2bf..9dcaaef 100644 --- a/src/bin/br.rs +++ b/src/bin/br.rs @@ -175,7 +175,13 @@ fn load_bytecode_from_bedrock_path(path: &Path) -> Option { /// Attempt to load bytecode from a file path. fn load_bytecode_from_file(path: &Path) -> Result { - load_bytecode_from_readable_source(std::fs::File::open(path)?, Some(path)) + // Canonicalize paths so that symbolic links to program files resolve to + // the real program directory, which could contain a symbols file. + let path = match path.canonicalize() { + Ok(canonical) => canonical, + Err(_) => path.to_path_buf(), + }; + load_bytecode_from_readable_source(std::fs::File::open(&path)?, Some(&path)) } /// Attempt to load bytecode from standard input. -- cgit v1.2.3-70-g09d2