Skip to main content

real_home_dir

Function real_home_dir 

Source
pub fn real_home_dir() -> Option<PathBuf>
Expand description

Get the real user’s home directory, accounting for sudo scenarios.

When running under sudo, dirs::home_dir() returns root’s home directory because $HOME is set to /root. This function checks for SUDO_USER and attempts to use that information.

Note: This crate forbids unsafe code, so we cannot use getpwnam_r. Instead, we use environment variables and construct the path.