diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-09 06:19:30 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-09 06:19:30 +0900 |
| commit | 880a5eaad9dcdfd31563385f11ba1f63d38cfd14 (patch) | |
| tree | 6f9de7b2b8331628a74287112711f65ae3eddc52 /crates/shirabe-external-packages/src/symfony/process | |
| parent | f3d60c7836da0d50d59a22cfd6e4692e3dc75581 (diff) | |
| download | php-shirabe-880a5eaad9dcdfd31563385f11ba1f63d38cfd14.tar.gz php-shirabe-880a5eaad9dcdfd31563385f11ba1f63d38cfd14.tar.zst php-shirabe-880a5eaad9dcdfd31563385f11ba1f63d38cfd14.zip | |
refactor(php-shim): use std::path::MAIN_SEPARATOR over a shim constant
The shim's DIRECTORY_SEPARATOR was hardcoded to "/", so every ported
`'\\' === DIRECTORY_SEPARATOR` check compared against a constant that
does not track the target platform. std::path::MAIN_SEPARATOR and
MAIN_SEPARATOR_STR carry the same meaning as PHP's constant and resolve
per platform, so the Windows branches are selected on Windows targets.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/process')
3 files changed, 17 insertions, 27 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 3c44b4ad..a00a302c 100644 --- a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs +++ b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs @@ -25,7 +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 shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" + if std::path::MAIN_SEPARATOR == '\\' && CMD_BUILTINS.contains(&shirabe_php_shim::strtolower(name).as_str()) { return Some(name.to_string()); @@ -39,7 +39,7 @@ impl ExecutableFinder { dirs.extend_from_slice(extra_dirs); let mut suffixes: Vec<String> = vec![]; - if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" { + if std::path::MAIN_SEPARATOR == '\\' { let path_ext = shirabe_php_shim::getenv("PATHEXT").map(|v| v.to_string_lossy().into_owned()); suffixes = self.suffixes.clone(); @@ -68,13 +68,9 @@ impl ExecutableFinder { for suffix in &suffixes { for dir in &dirs { let dir = if dir.is_empty() { "." } else { dir.as_str() }; - let file = format!( - "{dir}{}{name}{suffix}", - shirabe_php_shim::DIRECTORY_SEPARATOR - ); + let file = format!("{dir}{}{name}{suffix}", std::path::MAIN_SEPARATOR); if shirabe_php_shim::is_file(&file) - && (shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" - || shirabe_php_shim::is_executable(&file)) + && (std::path::MAIN_SEPARATOR == '\\' || shirabe_php_shim::is_executable(&file)) { return Some(file); } @@ -88,12 +84,9 @@ impl ExecutableFinder { } } - if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" + if std::path::MAIN_SEPARATOR == '\\' || name.len() - != shirabe_php_shim::strcspn( - name, - &format!("/{}", shirabe_php_shim::DIRECTORY_SEPARATOR), - ) + != shirabe_php_shim::strcspn(name, &format!("/{}", std::path::MAIN_SEPARATOR)) { return default.map(ToString::to_string); } diff --git a/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs b/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs index 72a28e7d..c4236743 100644 --- a/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs +++ b/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs @@ -17,7 +17,7 @@ pub struct WindowsPipes { impl WindowsPipes { pub fn new(_input: PhpMixed) -> Self { - // Windows-only path: never constructed on POSIX (DIRECTORY_SEPARATOR is "/"). + // Windows-only path: never constructed on POSIX (MAIN_SEPARATOR is '/'). todo!() } } diff --git a/crates/shirabe-external-packages/src/symfony/process/process.rs b/crates/shirabe-external-packages/src/symfony/process/process.rs index 3e4a818f..64ed3a84 100644 --- a/crates/shirabe-external-packages/src/symfony/process/process.rs +++ b/crates/shirabe-external-packages/src/symfony/process/process.rs @@ -245,7 +245,7 @@ impl Process { this.set_input(input)?; this.set_timeout(timeout)?; - this.use_file_handles = shirabe_php_shim::DIRECTORY_SEPARATOR == "\\"; + this.use_file_handles = std::path::MAIN_SEPARATOR == '\\'; Ok(this) } @@ -309,7 +309,7 @@ impl Process { .collect::<Vec<_>>() .join(" "); - if shirabe_php_shim::DIRECTORY_SEPARATOR != "\\" { + if std::path::MAIN_SEPARATOR != '\\' { // exec is mandatory to deal with sending a signal to the process cmd = format!("exec {}", cmd); } @@ -318,7 +318,7 @@ impl Process { CommandLine::String(s) => self.replace_placeholders(s, &env)?, }; - if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" { + if std::path::MAIN_SEPARATOR == '\\' { commandline = self.prepare_windows_command_line(&commandline, &mut env)?; } else if !self.use_file_handles && self.is_sigchild_enabled() { // last exit code is output on the fourth pipe and caught to work around --enable-sigchild @@ -414,12 +414,9 @@ impl Process { loop { self.check_timeout()?; let running = self.is_running() - && (shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" + && (std::path::MAIN_SEPARATOR == '\\' || self.process_pipes.as_ref().unwrap().are_open()); - self.read_pipes( - running, - shirabe_php_shim::DIRECTORY_SEPARATOR != "\\" || !running, - ); + self.read_pipes(running, std::path::MAIN_SEPARATOR != '\\' || !running); if !running { break; } @@ -644,7 +641,7 @@ impl Process { /// Enables or disables the TTY mode. pub fn set_tty(&mut self, tty: bool) -> anyhow::Result<&mut Self> { - if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" && tty { + if std::path::MAIN_SEPARATOR == '\\' && tty { return Err(RuntimeException::new( "TTY mode is not supported on Windows platform.".to_string(), ) @@ -743,7 +740,7 @@ impl Process { /// Creates the descriptors needed by the proc_open. fn get_descriptors(&mut self) -> Vec<Descriptor> { // TODO(plugin): $this->input instanceof \Iterator -> rewind() is not modeled. - if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" { + if std::path::MAIN_SEPARATOR == '\\' { self.process_pipes = Some(Box::new(WindowsPipes::new(self.input.clone()))); } else { self.process_pipes = Some(Box::new(UnixPipes::new( @@ -818,7 +815,7 @@ impl Process { self.read_pipes( running && blocking, - shirabe_php_shim::DIRECTORY_SEPARATOR != "\\" || !running, + std::path::MAIN_SEPARATOR != '\\' || !running, ); if !self.fallback_status.is_empty() && self.is_sigchild_enabled() { @@ -999,7 +996,7 @@ impl Process { Some(pid) => pid, }; - if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" { + if std::path::MAIN_SEPARATOR == '\\' { let mut output: Vec<String> = Vec::new(); let mut exit_code: i64 = 0; shirabe_php_shim::exec( @@ -1192,7 +1189,7 @@ impl Process { None | Some("") => return "\"\"".to_string(), Some(a) => a, }; - if shirabe_php_shim::DIRECTORY_SEPARATOR != "\\" { + if std::path::MAIN_SEPARATOR != '\\' { return format!("'{}'", argument.replace('\'', "'\\''")); } let mut argument = argument.to_string(); |
