Skip to content

Commit

Permalink
fix(path): fix home path
Browse files Browse the repository at this point in the history
  • Loading branch information
QaidVoid committed Dec 2, 2024
1 parent 115056f commit b4d3a53
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
Soar is a fast Linux package manager that doesn't suck. Works with static binaries, AppImages, and other portable stuff.
</p>

> [!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.
<div align="center">

| <img src="https://raw.githubusercontent.com/pkgforge/soar/refs/heads/autoplay/install.webp" /> | <img src="https://raw.githubusercontent.com/pkgforge/soar/refs/heads/autoplay/remove.webp" /> | <img src="https://raw.githubusercontent.com/pkgforge/soar/refs/heads/autoplay/download.webp" /> |
Expand Down
16 changes: 8 additions & 8 deletions src/core/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down Expand Up @@ -75,18 +75,18 @@ pub fn build_path(path: &str) -> Result<PathBuf> {
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);
}
Expand Down

0 comments on commit b4d3a53

Please sign in to comment.