summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2024-10-31 11:10:05 +1300
committerBen Bridle <ben@derelict.engineering>2024-10-31 11:10:05 +1300
commit0bf83f08a4099d90ac18f921b45f74124bcb4c62 (patch)
treec529adb255429342cf07ba8b70c5f9d4c393c1b4
parent4155047b3d6f7a1c5993ef8a8ed2244213a1c8d3 (diff)
downloadbedrock-pc-0bf83f08a4099d90ac18f921b45f74124bcb4c62.zip
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.
-rw-r--r--src/bin/br.rs8
1 files changed, 7 insertions, 1 deletions
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<Bytecode> {
/// Attempt to load bytecode from a file path.
fn load_bytecode_from_file(path: &Path) -> Result<Bytecode, std::io::Error> {
- 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.