Enhance convert_path_with_tilde_expansion to handle Windows (#4390)

This commit is contained in:
Max Novich
2025-08-28 14:32:39 -07:00
committed by GitHub
parent 74ce62d13d
commit 1d0c08b3d3
3 changed files with 59 additions and 27 deletions
@@ -36,11 +36,25 @@ pub fn read_recipe_file<P: AsRef<Path>>(recipe_path: P) -> Result<RecipeFile> {
fn convert_path_with_tilde_expansion(path: &Path) -> PathBuf {
if let Some(path_str) = path.to_str() {
// Handle exact "~" (Windows only to avoid changing behavior on Unix)
if cfg!(windows) && path_str == "~" {
if let Some(home_dir) = dirs::home_dir() {
return home_dir;
}
}
// Handle Unix-style "~/..."
if let Some(stripped) = path_str.strip_prefix("~/") {
if let Some(home_dir) = dirs::home_dir() {
return home_dir.join(stripped);
}
}
// Handle Windows-style "~\\..." (Windows only)
#[cfg(windows)]
if let Some(stripped) = path_str.strip_prefix("~\\") {
if let Some(home_dir) = dirs::home_dir() {
return home_dir.join(stripped);
}
}
}
PathBuf::from(path)
}