mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
core: resolve host_executable() rules during preflight
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::bash::parse_shell_lc_plain_commands;
|
||||
use std::path::Path;
|
||||
#[cfg(windows)]
|
||||
#[path = "windows_dangerous_commands.rs"]
|
||||
mod windows_dangerous_commands;
|
||||
@@ -52,6 +53,32 @@ fn is_git_global_option_with_inline_value(arg: &str) -> bool {
|
||||
) || ((arg.starts_with("-C") || arg.starts_with("-c")) && arg.len() > 2)
|
||||
}
|
||||
|
||||
pub(crate) fn executable_name_lookup_key(raw: &str) -> Option<String> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
Path::new(raw)
|
||||
.file_name()
|
||||
.and_then(|name| name.to_str())
|
||||
.map(|name| {
|
||||
let name = name.to_ascii_lowercase();
|
||||
for suffix in [".exe", ".cmd", ".bat", ".com"] {
|
||||
if let Some(stripped) = name.strip_suffix(suffix) {
|
||||
return stripped.to_string();
|
||||
}
|
||||
}
|
||||
name
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
Path::new(raw)
|
||||
.file_name()
|
||||
.and_then(|name| name.to_str())
|
||||
.map(std::borrow::ToOwned::to_owned)
|
||||
}
|
||||
}
|
||||
|
||||
/// Find the first matching git subcommand, skipping known global options that
|
||||
/// may appear before it (e.g., `-C`, `-c`, `--git-dir`).
|
||||
///
|
||||
@@ -61,7 +88,7 @@ pub(crate) fn find_git_subcommand<'a>(
|
||||
subcommands: &[&str],
|
||||
) -> Option<(usize, &'a str)> {
|
||||
let cmd0 = command.first().map(String::as_str)?;
|
||||
if !cmd0.ends_with("git") {
|
||||
if executable_name_lookup_key(cmd0).as_deref() != Some("git") {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user