From 7d9702669b6318192debc6961404ac2ff8dac57a Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Tue, 3 Oct 2023 09:00:23 +0200 Subject: [PATCH] fix: don't remove the '.11' from 'python3.11' binary file name (#366) closes https://github.com/prefix-dev/pixi/issues/317 When a numeric end is found on the binary, we don't remove it. --- src/cli/global/install.rs | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/cli/global/install.rs b/src/cli/global/install.rs index 1e71e9f3c..f3b38046c 100644 --- a/src/cli/global/install.rs +++ b/src/cli/global/install.rs @@ -17,6 +17,7 @@ use rattler_shell::{ shell::ShellEnum, }; use rattler_solve::{resolvo, SolverImpl}; +use std::ffi::OsStr; use std::{ path::{Path, PathBuf}, str::FromStr, @@ -208,12 +209,44 @@ async fn map_executables_to_global_bin_scripts<'a>( package_executables: &[&'a Path], bin_dir: &BinDir, ) -> miette::Result>> { + #[cfg(target_family = "windows")] + let extensions_list: Vec = if let Ok(pathext) = std::env::var("PATHEXT") { + pathext.split(';').map(|s| s.to_lowercase()).collect() + } else { + tracing::debug!("Could not find 'PATHEXT' variable, using a default list"); + [ + ".COM", ".EXE", ".BAT", ".CMD", ".VBS", ".VBE", ".JS", ".JSE", ".WSF", ".WSH", ".MSC", + ".CPL", + ] + .iter() + .map(|&s| s.to_lowercase()) + .collect() + }; + + #[cfg(target_family = "unix")] + // TODO: Find if there are more relevant cases, these cases are generated by our big friend GPT-4 + let extensions_list: Vec = vec![ + ".sh", ".bash", ".zsh", ".csh", ".tcsh", ".ksh", ".fish", ".py", ".pl", ".rb", ".lua", + ".php", ".tcl", ".awk", ".sed", + ] + .iter() + .map(|&s| s.to_owned()) + .collect(); + let BinDir(bin_dir) = bin_dir; let mut mappings = vec![]; + for exec in package_executables.iter() { - let file_name = exec - .file_stem() - .ok_or_else(|| miette::miette!("could not get filename from {}", exec.display()))?; + // Remove the extension of a file if it is in the list of known extensions. + let Some(file_name) = exec + .file_name() + .and_then(OsStr::to_str) + .map(str::to_lowercase) else { continue; }; + let file_name = extensions_list + .iter() + .find_map(|ext| file_name.strip_suffix(ext)) + .unwrap_or(file_name.as_str()); + let mut executable_script_path = bin_dir.join(file_name); if cfg!(windows) {