fix(username): avoid using whoami on android

Closes #6340

Co-Authored-By: AminurAlam <64137875+aminuralam@users.noreply.github.com>
This commit is contained in:
David Knaack 2024-10-21 19:10:17 +02:00
parent eaccc512f2
commit abad5e3de2

View File

@ -19,13 +19,13 @@ const USERNAME_ENV_VAR: &str = "USERNAME";
/// Does not display the username:
/// - If the option `username.detect_env_vars` is set with a negated environment variable [A]
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
#[cfg(not(test))]
#[cfg(not(any(test, target_os = "android")))]
let mut username = whoami::fallible::username()
.inspect_err(|e| log::debug!("Failed to get username {e:?}"))
.ok()
.or_else(|| context.get_env(USERNAME_ENV_VAR))?;
#[cfg(test)]
#[cfg(any(test, target_os = "android"))]
let mut username = context.get_env(USERNAME_ENV_VAR)?;
let mut module = context.new_module("username");