Skip to content

Commit c3bd788

Browse files
Copilotswissspidy
andcommitted
Improve PackageValidator for cross-platform compatibility
- Suppress unzip command output to avoid cluttering console - Use platform-appropriate null device (NUL on Windows, /dev/null on Unix) - Add proper output redirection for both version check and validation Co-authored-by: swissspidy <[email protected]>
1 parent f80b016 commit c3bd788

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/WP_CLI/PackageValidator.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ private static function is_unzip_available() {
7575

7676
if ( null === $is_available ) {
7777
// Check if unzip is in PATH by trying to get its version.
78-
$result = WP_CLI::launch(
79-
'unzip -v',
78+
// Suppress output to avoid cluttering the console.
79+
$null_device = '\\' === DIRECTORY_SEPARATOR ? 'NUL' : '/dev/null';
80+
$result = WP_CLI::launch(
81+
sprintf( 'unzip -v > %s 2>&1', $null_device ),
8082
false,
8183
true
8284
);
@@ -93,18 +95,24 @@ private static function is_unzip_available() {
9395
* @return true|\WP_Error True if valid, WP_Error if validation fails.
9496
*/
9597
private static function validate_with_unzip( $file_path ) {
98+
// Suppress output - use platform-appropriate null device.
99+
$null_device = '\\' === DIRECTORY_SEPARATOR ? 'NUL' : '/dev/null';
100+
$command = sprintf(
101+
'unzip -t %s > %s 2>&1',
102+
escapeshellarg( $file_path ),
103+
$null_device
104+
);
105+
96106
$result = WP_CLI::launch(
97-
sprintf( 'unzip -t %s', escapeshellarg( $file_path ) ),
107+
$command,
98108
false,
99109
true
100110
);
101111

102112
if ( 0 !== $result->return_code ) {
103113
return new \WP_Error(
104114
'package_corrupted',
105-
sprintf(
106-
'Package file failed zip integrity check. This usually indicates a corrupted or incomplete download.'
107-
)
115+
'Package file failed zip integrity check. This usually indicates a corrupted or incomplete download.'
108116
);
109117
}
110118

0 commit comments

Comments
 (0)