mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
fix/uutils ~ support function/util (aka, applet) symlink aliasing where possible
## [why] `std::env::current_exe()` has platform dependent behavior and will often return the target binary, not the symlink name, when the binary is executed via symlink. So, to support symlinking, the first (0th) arg from `std::env::args()` is used, when possible, with fallback to `std::env::current_ext()` if args are missing or empty. - ref: <https://github.com/rust-lang/rust/issues/43617>
This commit is contained in:
parent
e759e852a9
commit
c457dfbbc4
1 changed files with 8 additions and 2 deletions
|
@ -10,7 +10,7 @@
|
|||
// spell-checker:ignore (acronyms/names) Gehring
|
||||
// spell-checker:ignore (rustlang) clippy concat rustlang
|
||||
// spell-checker:ignore (uutils) coreutils uucore uumain uutils sigpipe
|
||||
// spell-checker:ignore (shell) busybox
|
||||
// spell-checker:ignore (shell) busybox symlinks
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/uutils_crates.rs"));
|
||||
|
||||
|
@ -24,7 +24,13 @@ use std::io::Write;
|
|||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
lazy_static! {
|
||||
static ref BINARY_PATH: std::path::PathBuf = std::env::current_exe().unwrap();
|
||||
static ref BINARY_PATH: std::path::PathBuf = {
|
||||
// support symlinks by using args[0], when possible, with fallback to current_exe()
|
||||
match std::env::args().next() {
|
||||
Some(ref s) if !s.is_empty() => std::path::PathBuf::from(s),
|
||||
_ => std::env::current_exe().unwrap(),
|
||||
}
|
||||
};
|
||||
static ref NAME: &'static str = &*BINARY_PATH.file_stem().unwrap().to_str().unwrap();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue