-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Description
Background
I was attempting to use std::env::current_exe() to figure out how my program was invoked so I could respond with convenience code paths (analogous to how gpgv is basically a shortcut/alias for gpg --verify) when I noticed inconsistent behavior between OS X and Linux when the program was invoked via a symbolic link.
Steps to Reproduce
test.rs
fn main() {
println!("{:?}", std::env::current_exe());
}$ rustc test.rs
$ ln test one
$ ln -s test two
$ ./test
$ ./one
$ ./twoFor convenience I have bundled these in a repo: jeffweiss/rust-current_exe
Rust Version
rustc 1.19.0 (0ade339 2017-07-17)
Expected Behavior
On all platforms, I would expect to get:
Ok("/home/jweiss/devel/jeffweiss/rust-current_exe/test")
Ok("/home/jweiss/devel/jeffweiss/rust-current_exe/one")
Ok("/home/jweiss/devel/jeffweiss/rust-current_exe/two")
Actual Behavior
On Mac OS X, I get:
Ok("/home/jweiss/devel/jeffweiss/rust-current_exe/test")
Ok("/home/jweiss/devel/jeffweiss/rust-current_exe/one")
Ok("/home/jweiss/devel/jeffweiss/rust-current_exe/two")
On Linux, I get:
Ok("/home/jweiss/devel/jeffweiss/rust-current_exe/test")
Ok("/home/jweiss/devel/jeffweiss/rust-current_exe/one")
Ok("/home/jweiss/devel/jeffweiss/rust-current_exe/test")
Related Documentation
The documentation for std::env::current_exe implies that if you run current_exe from the symlink, you'll get the name of the symlink, not the dereferenced target of the symlink; however, the documentation's example does not actually include a symbolic link (ln -s), but rather a hard link (ln).