Skip to content

Commit 738c6d2

Browse files
authored
Always use ZIP archives for downloads (#333)
1 parent 347b431 commit 738c6d2

4 files changed

Lines changed: 24 additions & 50 deletions

File tree

features/core-download.feature

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Feature: Download WordPress
1515
When I run `wp core download`
1616
And save STDOUT 'Downloading WordPress ([\d\.]+)' as {VERSION}
1717
Then the wp-settings.php file should exist
18-
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-en_US.tar.gz file should exist
18+
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-en_US.zip file should exist
1919

2020
When I run `mkdir inner`
2121
And I run `cd inner && wp core download`
@@ -40,7 +40,7 @@ Feature: Download WordPress
4040
Then the wp-settings.php file should exist
4141
And STDOUT should contain:
4242
"""
43-
Using cached file '{SUITE_CACHE_DIR}/core/wordpress-{VERSION}-en_US.tar.gz'...
43+
Using cached file '{SUITE_CACHE_DIR}/core/wordpress-{VERSION}-en_US.zip'...
4444
"""
4545

4646
Scenario: Localized install
@@ -49,7 +49,7 @@ Feature: Download WordPress
4949
When I run `wp core download --version=4.4.2 --locale=de_DE`
5050
And save STDOUT 'Downloading WordPress ([\d\.]+)' as {VERSION}
5151
Then the wp-settings.php file should exist
52-
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-de_DE.tar.gz file should exist
52+
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-de_DE.zip file should exist
5353

5454
Scenario: Error when requested locale is not available for the latest version
5555
Given an empty directory
@@ -150,7 +150,7 @@ Feature: Download WordPress
150150
When I run `wp core download --version=4.4.1`
151151
Then STDOUT should contain:
152152
"""
153-
md5 hash verified: 1907d1dbdac7a009d89224a516496b8d
153+
md5 hash verified: 0c87de03eb3d76467cd0d3ab7268f1fd
154154
Success: WordPress downloaded.
155155
"""
156156

@@ -328,7 +328,7 @@ Feature: Download WordPress
328328
And STDOUT should contain:
329329
"""
330330
Downloading WordPress 4.6-RC2 (en_US)...
331-
md5 hash verified: 90c93a15092b2d5d4c960ec1fc183e07
331+
md5 hash verified: dbf4a8fe1c54d1e3e28532402da9a743
332332
Success: WordPress downloaded.
333333
"""
334334

@@ -344,8 +344,8 @@ Feature: Download WordPress
344344

345345
When I run `wp core version`
346346
Then save STDOUT as {VERSION}
347-
And the {SUITE_CACHE_DIR}/core/wordpress-latest-en_US.tar.gz file should not exist
348-
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-en_US.tar.gz file should exist
347+
And the {SUITE_CACHE_DIR}/core/wordpress-latest-en_US.zip file should not exist
348+
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-en_US.zip file should exist
349349

350350
Scenario: Fail if path can't be created
351351
Given an empty directory
@@ -503,14 +503,14 @@ Feature: Download WordPress
503503

504504
When I run `wp core download --version=4.5 --locale=de_DE`
505505
Then the wp-content directory should exist
506-
And the wordpress-4.5-de_DE.tar.gz file should not exist
506+
And the wordpress-4.5-de_DE.zip file should not exist
507507

508508
Scenario: Core download with extract parameter should unzip the download file
509509
Given an empty directory
510510

511511
When I run `wp core download --version=4.5 --locale=de_DE --extract`
512512
Then the wp-content directory should exist
513-
And the wordpress-4.5-de_DE.tar.gz file should not exist
513+
And the wordpress-4.5-de_DE.zip file should not exist
514514

515515
Scenario: Core download with extract parameter should unzip the download file (already cached)
516516
Given an empty directory
@@ -519,23 +519,23 @@ Feature: Download WordPress
519519
And I run `rm -rf *`
520520
And I run `wp core download --version=4.5 --locale=de_DE --extract`
521521
Then the wp-content directory should exist
522-
And the wordpress-4.5-de_DE.tar.gz file should not exist
522+
And the wordpress-4.5-de_DE.zip file should not exist
523523

524524
Scenario: Core download with no-extract should not unzip the download file
525525
Given an empty directory
526526

527527
When I run `wp core download --version=4.5 --locale=de_DE --no-extract`
528528
Then the wp-content directory should not exist
529-
And the wordpress-4.5-de_DE.tar.gz file should exist
529+
And the wordpress-4.5-de_DE.zip file should exist
530530

531531
Scenario: Core download with no-extract should not unzip the download file (already cached)
532532
Given an empty directory
533533

534534
When I run `wp core download --version=4.5 --locale=de_DE --no-extract`
535-
And I run `rm -rf wordpress-4.5-de_DE.tar.gz`
535+
And I run `rm -rf wordpress-4.5-de_DE.zip`
536536
And I run `wp core download --version=4.5 --locale=de_DE --no-extract`
537537
Then the wp-content directory should not exist
538-
And the wordpress-4.5-de_DE.tar.gz file should exist
538+
And the wordpress-4.5-de_DE.zip file should exist
539539

540540
Scenario: Error when using both --skip-content and --no-extract
541541
Given an empty directory

features/core-install.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ Feature: Install WordPress core
291291
5.6
292292
"""
293293
And the wp-settings.php file should exist
294-
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-de_DE.tar.gz file should exist
294+
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-de_DE.zip file should exist
295295

296296
When I run `wp config create --dbname={DB_NAME} --dbuser={DB_USER} --dbpass={DB_PASSWORD} --dbhost={DB_HOST} --locale=de_DE --skip-check`
297297
Then STDOUT should be:

features/core-update.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ Feature: Update WordPress core
226226
"""
227227
And the {SUITE_CACHE_DIR}/core directory should contain:
228228
"""
229-
wordpress-6.5.2-en_US.tar.gz
229+
wordpress-6.5.2-en_US.zip
230230
wordpress-6.5.5-partial-1-en_US.zip
231231
"""
232232

@@ -246,8 +246,8 @@ Feature: Update WordPress core
246246
"""
247247
And the {SUITE_CACHE_DIR}/core directory should contain:
248248
"""
249-
wordpress-6.4.1-en_US.tar.gz
250-
wordpress-6.5.2-en_US.tar.gz
249+
wordpress-6.4.1-en_US.zip
250+
wordpress-6.5.2-en_US.zip
251251
wordpress-6.5.5-no-content-en_US.zip
252252
wordpress-6.5.5-partial-1-en_US.zip
253253
"""

src/Core_Command.php

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,7 @@ public function download( $args, $assoc_args ) {
230230
$version = 'nightly';
231231
}
232232

233-
// Nightly builds and skip content are only available in .zip format.
234-
$extension = ( ( 'nightly' === $version ) || $skip_content )
235-
? 'zip'
236-
: 'tar.gz';
237-
238-
$download_url = $this->get_download_url( $version, $locale, $extension );
233+
$download_url = $this->get_download_url( $version, $locale );
239234
} else {
240235
$wp_org_api = new WpOrgApi( [ 'insecure' => $insecure ] );
241236
try {
@@ -256,9 +251,6 @@ public function download( $args, $assoc_args ) {
256251
}
257252
$version = $offer['current'];
258253
$download_url = $offer['download'];
259-
if ( ! $skip_content ) {
260-
$download_url = str_replace( '.zip', '.tar.gz', $download_url );
261-
}
262254
}
263255

264256
if ( 'nightly' === $version && 'en_US' !== $locale ) {
@@ -277,18 +269,7 @@ public function download( $args, $assoc_args ) {
277269
WP_CLI::log( "Downloading WordPress {$version} ({$locale})..." );
278270
}
279271

280-
$path_parts = pathinfo( $download_url );
281-
$extension = 'tar.gz';
282-
if ( isset( $path_parts['extension'] ) && 'zip' === $path_parts['extension'] ) {
283-
$extension = 'zip';
284-
if ( $extract && ! class_exists( 'ZipArchive' ) ) {
285-
WP_CLI::error( 'Extracting a zip file requires ZipArchive.' );
286-
}
287-
}
288-
289-
if ( $skip_content && 'zip' !== $extension ) {
290-
WP_CLI::error( 'Skip content is only available for ZIP files.' );
291-
}
272+
$extension = 'zip';
292273

293274
$cache = WP_CLI::get_cache();
294275
if ( $from_url ) {
@@ -316,8 +297,6 @@ public function download( $args, $assoc_args ) {
316297
}
317298

318299
if ( ! $cache_file || $bad_cache ) {
319-
// We need to use a temporary file because piping from cURL to tar is flaky
320-
// on MinGW (and probably in other environments too).
321300
$temp = Utils\get_temp_dir() . uniqid( 'wp_' ) . ".{$extension}";
322301
register_shutdown_function(
323302
function () use ( $temp ) {
@@ -1652,21 +1631,16 @@ public function update_db( $args, $assoc_args ) {
16521631
}
16531632

16541633
/**
1655-
* Gets download url based on version, locale and desired file type.
1634+
* Gets download url based on version and locale.
16561635
*
16571636
* @param $version
16581637
* @param string $locale
1659-
* @param string $file_type
16601638
* @return string
16611639
*/
1662-
private function get_download_url( $version, $locale = 'en_US', $file_type = 'zip' ) {
1640+
private function get_download_url( $version, $locale = 'en_US' ) {
16631641

16641642
if ( 'nightly' === $version ) {
1665-
if ( 'zip' === $file_type ) {
1666-
return 'https://wordpress.org/nightly-builds/wordpress-latest.zip';
1667-
} else {
1668-
WP_CLI::error( 'Nightly builds are only available in .zip format.' );
1669-
}
1643+
return 'https://wordpress.org/nightly-builds/wordpress-latest.zip';
16701644
}
16711645

16721646
$locale_subdomain = 'en_US' === $locale ? '' : substr( $locale, 0, 2 ) . '.';
@@ -1676,7 +1650,7 @@ private function get_download_url( $version, $locale = 'en_US', $file_type = 'zi
16761650
$version = substr( $version, 0, -2 );
16771651
}
16781652

1679-
return "https://{$locale_subdomain}wordpress.org/wordpress-{$version}{$locale_suffix}.{$file_type}";
1653+
return "https://{$locale_subdomain}wordpress.org/wordpress-{$version}{$locale_suffix}.zip";
16801654
}
16811655

16821656
/**
@@ -1722,7 +1696,7 @@ private function find_latest_offer_for_locale( $locale, $insecure ) {
17221696
) {
17231697
return [
17241698
'current' => $translation['version'],
1725-
'download' => $this->get_download_url( $translation['version'], $locale, 'zip' ),
1699+
'download' => $this->get_download_url( $translation['version'], $locale ),
17261700
];
17271701
}
17281702
}

0 commit comments

Comments
 (0)