Skip to content

Commit

Permalink
Correctly fall back to home folder if HOME is unset (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko authored Jan 15, 2024
1 parent 65daae9 commit de7c69f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ _Unreleased_

- Fixed default generated script reference. #527

- Correctly fall back to home folder if HOME is unset. #533

<!-- released start -->

## 0.16.0
Expand Down
19 changes: 16 additions & 3 deletions rye/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,22 @@ pub fn init() -> Result<(), Error> {
let home = if let Some(rye_home) = env::var_os("RYE_HOME") {
PathBuf::from(rye_home)
} else {
simple_home_dir::home_dir()
.map(|x| x.join(".rye"))
.ok_or_else(|| anyhow!("could not determine home folder"))?
{
// ironically the deprecated home dir implementation is
// still the only one that falls back to getpwuid.
// Fixes https://github.com/mitsuhiko/rye/issues/532
#[cfg(unix)]
{
#[allow(deprecated)]
std::env::home_dir()
}
#[cfg(not(unix))]
{
simple_home_dir::home_dir()
}
}
.map(|x| x.join(".rye"))
.ok_or_else(|| anyhow!("could not determine home folder"))?
};
*APP_DIR.lock().unwrap() = Some(Box::leak(Box::new(home)));
Ok(())
Expand Down

0 comments on commit de7c69f

Please sign in to comment.