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/process.rs | |
| 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/process.rs')
| -rw-r--r-- | crates/shirabe-external-packages/src/symfony/process/process.rs | 23 |
1 files changed, 10 insertions, 13 deletions
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(); |
