From b7ab1405eef1f2f35d451923a6bf2bcd52cda8a3 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Fri, 21 May 2021 19:11:09 +0800 Subject: [PATCH] fix home path issue on some linux build --- libs/hbb_common/src/config.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/libs/hbb_common/src/config.rs b/libs/hbb_common/src/config.rs index f98be4162..72eee9309 100644 --- a/libs/hbb_common/src/config.rs +++ b/libs/hbb_common/src/config.rs @@ -148,6 +148,17 @@ fn patch(path: PathBuf) -> PathBuf { .into(); #[cfg(target_os = "macos")] return _tmp.replace("Application Support", "Preferences").into(); + #[cfg(target_os = "linux")] + { + if _tmp == "/root" { + if let Ok(output) = std::process::Command::new("whoami").output() { + let user = String::from_utf8_lossy(&output.stdout).to_string().trim().to_owned(); + if user != "root" { + return format!("/home/{}", user).into(); + } + } + } + } } path } @@ -269,11 +280,10 @@ impl Config { } #[cfg(target_os = "linux")] { - if let Some(path) = dirs_next::home_dir().as_mut() { - path.push(format!(".local/share/logs/{}", APP_NAME)); - std::fs::create_dir_all(&path).ok(); - return path.clone(); - } + let mut path = Self::get_home(); + path.push(format!(".local/share/logs/{}", APP_NAME)); + std::fs::create_dir_all(&path).ok(); + return path; } if let Some(path) = Self::path("").parent() { let mut path: PathBuf = path.into();