diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-09 06:25:03 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-09 06:25:03 +0900 |
| commit | 6dd09abb33d86e1aa737667f9e15a18ed41d52e1 (patch) | |
| tree | 83f961fb8657c3b5c8440caecaf61a52fdc3a2de /crates/shirabe-external-packages/src/symfony/process/executable_finder.rs | |
| parent | 880a5eaad9dcdfd31563385f11ba1f63d38cfd14 (diff) | |
| download | php-shirabe-6dd09abb33d86e1aa737667f9e15a18ed41d52e1.tar.gz php-shirabe-6dd09abb33d86e1aa737667f9e15a18ed41d52e1.tar.zst php-shirabe-6dd09abb33d86e1aa737667f9e15a18ed41d52e1.zip | |
refactor(external-packages): test for Windows with cfg!(windows)
MAIN_SEPARATOR is the path separator; PHP's `'\\' === DIRECTORY_SEPARATOR`
uses it as an OS test only because PHP has no dedicated one. cfg!(windows)
says what the branch actually selects on, and leaves MAIN_SEPARATOR to the
sites that really join or split paths.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/process/executable_finder.rs')
| -rw-r--r-- | crates/shirabe-external-packages/src/symfony/process/executable_finder.rs | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs index a00a302c..cd7d378f 100644 --- a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs +++ b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs @@ -25,9 +25,7 @@ impl ExecutableFinder { pub fn find(&self, name: &str, default: Option<&str>, extra_dirs: &[String]) -> Option<String> { // windows built-in commands that are present in cmd.exe should not be resolved using PATH as they do not exist as exes - if std::path::MAIN_SEPARATOR == '\\' - && CMD_BUILTINS.contains(&shirabe_php_shim::strtolower(name).as_str()) - { + if cfg!(windows) && CMD_BUILTINS.contains(&shirabe_php_shim::strtolower(name).as_str()) { return Some(name.to_string()); } @@ -39,7 +37,7 @@ impl ExecutableFinder { dirs.extend_from_slice(extra_dirs); let mut suffixes: Vec<String> = vec![]; - if std::path::MAIN_SEPARATOR == '\\' { + if cfg!(windows) { let path_ext = shirabe_php_shim::getenv("PATHEXT").map(|v| v.to_string_lossy().into_owned()); suffixes = self.suffixes.clone(); @@ -70,7 +68,7 @@ impl ExecutableFinder { let dir = if dir.is_empty() { "." } else { dir.as_str() }; let file = format!("{dir}{}{name}{suffix}", std::path::MAIN_SEPARATOR); if shirabe_php_shim::is_file(&file) - && (std::path::MAIN_SEPARATOR == '\\' || shirabe_php_shim::is_executable(&file)) + && (cfg!(windows) || shirabe_php_shim::is_executable(&file)) { return Some(file); } @@ -84,7 +82,7 @@ impl ExecutableFinder { } } - if std::path::MAIN_SEPARATOR == '\\' + if cfg!(windows) || name.len() != shirabe_php_shim::strcspn(name, &format!("/{}", std::path::MAIN_SEPARATOR)) { |
