Fix Windows: use where instead of /usr/bin/env which for MySQL binary detection#6338
Fix Windows: use where instead of /usr/bin/env which for MySQL binary detection#6338Copilot wants to merge 4 commits into
where instead of /usr/bin/env which for MySQL binary detection#6338Conversation
…ary_path() and related functions Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
where instead of /usr/bin/env which for MySQL binary detection
|
@copilot can we make this more testable with behat coverage? |
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Added Behat coverage in commit
|
There was a problem hiding this comment.
Pull request overview
This PR fixes Windows failures during PHAR verification and related commands by avoiding Unix-only /usr/bin/env which ... invocations, improving MySQL/MariaDB binary detection on Windows, and hardening command execution against paths containing spaces.
Changes:
- Update MySQL/MariaDB binary discovery to use
whereon Windows (and first-line selection when multiple matches are returned). - Ensure version detection avoids
/usr/bin/envon Windows viaforce_env_on_nix_systems(). - Escape detected binary paths with
escapeshellarg()before embedding them into command strings. - Add Behat coverage for MySQL binary path detection and a
wp cli inforegression scenario under Windows simulation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

On Windows,
wp cli updatefails with "The downloaded PHAR is broken" because the PHAR verification runswp --info, which callsget_mysql_binary_path()using/usr/bin/env which mysql— both/usr/bin/envandwhichdon't exist on Windows, causingproc_open()to emit a fatal error.Changes
get_mysql_binary_path()— useswhere mysql/where mariadbon Windows; takes only the first line of output sincewherecan return multiple matchesget_mysql_version()— usesforce_env_on_nix_systems()which already strips/usr/bin/envon Windowsget_sql_dump_command()/get_sql_check_command()— usewhere mariadb-dump/where mariadb-checkon Windowsescapeshellarg()to handle paths containing spaces (e.g.C:\Program Files\MySQL\...\mysql.exe)Tests
features/utils.feature— verifiesget_mysql_binary_path()returns a non-empty path on Linux with MySQL available (@require-mysql @skip-windows), and that it returns an empty string gracefully when simulating Windows viaWP_CLI_TEST_IS_WINDOWS=1(wherewhereis unavailable on Linux)features/cli-info.feature— regression test that runsWP_CLI_TEST_IS_WINDOWS=1 wp cli infoand asserts the command completes successfully with theMySQL binary:field present, directly covering the original crash scenario