From b4d3a53658089edfb26ced1199cf03f968c03d97 Mon Sep 17 00:00:00 2001 From: Rabindra Dhakal Date: Mon, 2 Dec 2024 22:32:43 +0545 Subject: [PATCH] fix(path): fix home path --- README.md | 5 +++++ src/core/util.rs | 16 ++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 36c07e7..6cd8a9d 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,11 @@ Soar is a fast Linux package manager that doesn't suck. Works with static binaries, AppImages, and other portable stuff.

+> [!WARNING] +> **Breaking Changes Ahead** +> +> The next version of Soar will introduce significant changes, including breaking changes to configuration formats, and behavior. Please review the CHANGELOG before upgrading. +
| | | | diff --git a/src/core/util.rs b/src/core/util.rs index c696ef9..dfbc2e9 100644 --- a/src/core/util.rs +++ b/src/core/util.rs @@ -44,7 +44,7 @@ pub fn home_path() -> String { .or_else(|_| env::var("LOGNAME")) .or_else(|_| get_username().map_err(|_| ())) .unwrap_or_else(|_| panic!("Couldn't determine username. Please fix the system.")); - format!("home/{}", username) + format!("/home/{}", username) }) } @@ -75,18 +75,18 @@ pub fn build_path(path: &str) -> Result { var_name.push(chars.next().unwrap()); } if !var_name.is_empty() { - let expanded = env::var(&var_name) - .with_context(|| format!("Environment variable ${} not found", var_name))?; + let expanded = if var_name == "HOME" { + home_path() + } else { + env::var(&var_name) + .with_context(|| format!("Environment variable ${} not found", var_name))? + }; result.push_str(&expanded); } else { result.push('$'); } } else if c == '~' && result.is_empty() { - if let Some(home) = env::var_os("HOME").or_else(|| env::var_os("USERPROFILE")) { - result.push_str(home.to_string_lossy().as_ref()); - } else { - result.push('~'); - } + result.push_str(&home_path()) } else { result.push(c); }