| 747 | } |
| 748 | |
| 749 | fn which_tracedecay_from( |
| 750 | current_exe: Option<&Path>, |
| 751 | path_var: Option<&std::ffi::OsStr>, |
| 752 | cargo_target_dir: Option<&Path>, |
| 753 | ) -> Option<String> { |
| 754 | if let Some(exe) = current_exe |
| 755 | .filter(|exe| is_tracedecay_exe(exe) && !is_cargo_target_binary(exe, cargo_target_dir)) |
| 756 | { |
| 757 | return Some(normalize_path_separators(&exe.to_string_lossy())); |
| 758 | } |
| 759 | |
| 760 | let path_match = path_var.and_then(|path_var| { |
| 761 | std::env::split_paths(path_var).find_map(|dir| { |
| 762 | let candidate = dir.join(tracedecay_bin_name()); |
| 763 | (candidate.exists() && !is_cargo_target_binary(&candidate, cargo_target_dir)) |
| 764 | .then(|| normalize_path_separators(&candidate.to_string_lossy())) |
| 765 | }) |
| 766 | }); |
| 767 | path_match.or_else(|| { |
| 768 | current_exe |
| 769 | .filter(|exe| is_tracedecay_exe(exe)) |
| 770 | .map(|exe| normalize_path_separators(&exe.to_string_lossy())) |
| 771 | }) |
| 772 | } |
| 773 | |
| 774 | fn tracedecay_bin_name() -> String { |
| 775 | format!("tracedecay{}", std::env::consts::EXE_SUFFIX) |