diff --git a/Cargo.toml b/Cargo.toml index 6b1a5e2..54e2a72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "which" -version = "7.0.0" +version = "7.0.1" edition = "2021" rust-version = "1.70" authors = ["Harry Fei , Jacob Kiesel "] diff --git a/src/finder.rs b/src/finder.rs index 66568f5..7c59a5e 100644 --- a/src/finder.rs +++ b/src/finder.rs @@ -266,20 +266,22 @@ fn tilde_expansion(p: &PathBuf) -> Cow<'_, PathBuf> { let mut component_iter = p.components(); if let Some(Component::Normal(o)) = component_iter.next() { if o == "~" { - let mut new_path = env_home_dir().unwrap_or_default(); - new_path.extend(component_iter); - #[cfg(feature = "tracing")] - tracing::trace!( - "found tilde, substituting in user's home directory to get {}", - new_path.display() - ); - Cow::Owned(new_path) - } else { - Cow::Borrowed(p) + let new_path = env_home_dir(); + if let Some(mut new_path) = new_path { + new_path.extend(component_iter); + #[cfg(feature = "tracing")] + tracing::trace!( + "found tilde, substituting in user's home directory to get {}", + new_path.display() + ); + return Cow::Owned(new_path); + } else { + #[cfg(feature = "tracing")] + tracing::trace!("found tilde in path, but user's home directory couldn't be found"); + } } - } else { - Cow::Borrowed(p) } + Cow::Borrowed(p) } #[cfg(target_os = "windows")]