Fix. Linux, run_cmds, trim new line (#7579)

* Fix. Linux, run_cmds, trim new line

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* add tests

Signed-off-by: fufesou <shuanglongchen@yeah.net>

---------

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2024-04-02 14:47:13 +08:00
committed by GitHub
parent 58fe95d6fd
commit 2e11a8b458
3 changed files with 54 additions and 3 deletions

View File

@@ -406,10 +406,12 @@ fn patch(path: PathBuf) -> PathBuf {
#[cfg(target_os = "linux")]
{
if _tmp == "/root" {
if let Ok(user) = crate::platform::linux::run_cmds("whoami") {
if let Ok(user) = crate::platform::linux::run_cmds_trim_newline("whoami") {
if user != "root" {
let cmd = format!("getent passwd '{}' | awk -F':' '{{print $6}}'", user);
if let Ok(output) = crate::platform::linux::run_cmds(&cmd) {
if let Ok(output) =
crate::platform::linux::run_cmds_trim_newline(&cmd)
{
return output.into();
}
return format!("/home/{user}").into();