From 85310221f0512bf1aeefc49ead8a1e11bda55990 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 05:01:59 +0200 Subject: Adding upstream version 126.0.1. Signed-off-by: Daniel Baumann --- toolkit/crashreporter/client/app/src/config.rs | 86 ++++++++++++++++---------- 1 file changed, 54 insertions(+), 32 deletions(-) (limited to 'toolkit/crashreporter/client/app/src/config.rs') diff --git a/toolkit/crashreporter/client/app/src/config.rs b/toolkit/crashreporter/client/app/src/config.rs index 4e919395e2..7eef674ea8 100644 --- a/toolkit/crashreporter/client/app/src/config.rs +++ b/toolkit/crashreporter/client/app/src/config.rs @@ -370,40 +370,16 @@ impl Config { // sense that if it were to rely on anything, it would be the `Config` (and that may change in // the future). pub fn sibling_program_path>(&self, program: N) -> PathBuf { - // Expect shouldn't ever panic here because we need more than one argument to run - // the program in the first place (we've already previously iterated args). - // - // We use argv[0] rather than `std::env::current_exe` because `current_exe` doesn't define - // how symlinks are treated, and we want to support running directly from the local build - // directory (which uses symlinks on linux and macos). - let self_path = PathBuf::from(std::env::args_os().next().expect("failed to get argv[0]")); + let self_path = self_path(); let exe_extension = self_path.extension().unwrap_or_default(); - - let mut program_path = self_path.clone(); - // Pop the executable off to get the parent directory. - program_path.pop(); - program_path.push(program.as_ref()); - program_path.set_extension(exe_extension); - - if !program_path.exists() && cfg!(all(not(mock), target_os = "macos")) { - // On macOS the crash reporter client is shipped as an application bundle contained - // within Firefox's main application bundle. So when it's invoked its current working - // directory looks like: - // Firefox.app/Contents/MacOS/crashreporter.app/Contents/MacOS/ - // The other applications we ship with Firefox are stored in the main bundle - // (Firefox.app/Contents/MacOS/) so we we need to go back three directories - // to reach them. - - // 4 pops: 1 for the path that was just pushed, and 3 more for - // `crashreporter.app/Contents/MacOS`. - for _ in 0..4 { - program_path.pop(); - } - program_path.push(program.as_ref()); - program_path.set_extension(exe_extension); + if !exe_extension.is_empty() { + let mut p = program.as_ref().to_os_string(); + p.push("."); + p.push(exe_extension); + sibling_path(p) + } else { + sibling_path(program) } - - program_path } cfg_if::cfg_if! { @@ -508,6 +484,52 @@ impl Config { } } +/// Get the path of a file that is a sibling of the crashreporter. +/// +/// On MacOS, this assumes that the crashreporter is its own application bundle within the main +/// program bundle. On other platforms this assumes siblings reside in the same directory as +/// the crashreporter. +/// +/// The returned path isn't guaranteed to exist. +pub fn sibling_path>(file: N) -> PathBuf { + // Expect shouldn't ever panic here because we need more than one argument to run + // the program in the first place (we've already previously iterated args). + // + // We use argv[0] rather than `std::env::current_exe` because `current_exe` doesn't define + // how symlinks are treated, and we want to support running directly from the local build + // directory (which uses symlinks on linux and macos). + let dir_path = { + let mut path = self_path(); + // Pop the executable off to get the parent directory. + path.pop(); + path + }; + + let mut path = dir_path.join(file.as_ref()); + + if !path.exists() && cfg!(all(not(mock), target_os = "macos")) { + // On macOS the crash reporter client is shipped as an application bundle contained + // within Firefox's main application bundle. So when it's invoked its current working + // directory looks like: + // Firefox.app/Contents/MacOS/crashreporter.app/Contents/MacOS/ + // The other applications we ship with Firefox are stored in the main bundle + // (Firefox.app/Contents/MacOS/) so we we need to go back three directories + // to reach them. + path = dir_path; + // 3 pops for `crashreporter.app/Contents/MacOS`. + for _ in 0..3 { + path.pop(); + } + path.push(file.as_ref()); + } + + path +} + +fn self_path() -> PathBuf { + PathBuf::from(std::env::args_os().next().expect("failed to get argv[0]")) +} + fn env_bool>(name: K) -> bool { std::env::var(name).map(|s| !s.is_empty()).unwrap_or(false) } -- cgit v1.2.3