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 get the actual invoking user’s home directory instead.

Priority:

  1. If SUDO_USER is set, try to get that user’s home directory
  2. Fall back to dirs::home_dir() (which reads $HOME or uses system APIs)