Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion features/core.feature
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ Feature: Manage WordPress installation
When I run `wp core update --version=3.8.1 --force`
Then STDOUT should contain:
"""
Using cached file '{SUITE_CACHE_DIR}/core/en_US-3.8.1.tar.gz'...
Using cached file '{SUITE_CACHE_DIR}/core/en_US-3.8.1.zip'...
"""
And STDOUT should not contain:
"""
Expand Down Expand Up @@ -510,3 +510,52 @@ Feature: Manage WordPress installation
"""
Warning: The 'en_GB' language is active.
"""

Scenario: Ensure file cache isn't corrupted by a ZIP masquerading as a gzipped TAR, part one
Given a WP install
And an empty cache
And I run `mkdir -p {SUITE_CACHE_DIR}/core; wget -O {SUITE_CACHE_DIR}/core/en_US-4.0.tar.gz https://wordpress.org/wordpress-4.0.zip`

When I run `wp core download --version=4.0 --force`
Then STDOUT should contain:
"""
Success: WordPress downloaded
"""
And STDERR should contain:
"""
Warning: Extraction failed, downloading a new copy...
"""

When I run `wp core version`
Then STDOUT should be:
"""
4.0
"""

Scenario: Ensure file cache isn't corrupted by core update, part two
Given a WP install
And an empty cache

When I run `wp core download --version=4.0 --force`
Then STDOUT should contain:
"""
Success: WordPress downloaded
"""

When I run `wp core version`
Then STDOUT should be:
"""
4.0
"""

When I run `wp core update --version=4.0 --force`
Then STDOUT should contain:
"""
Success: WordPress updated successfully
"""

When I run `wp core version`
Then STDOUT should be:
"""
4.0
"""
8 changes: 5 additions & 3 deletions php/WP_CLI/CoreUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ function download_package( $package ) {
if ( empty( $package ) )
return new WP_Error( 'no_package', $this->strings['no_package'] );

$temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.tar.gz';
$ext = pathinfo( $package, PATHINFO_EXTENSION );

$temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.' . $ext;

$cache = WP_CLI::get_cache();
$update = $GLOBALS['wp_cli_update_obj'];
$cache_key = "core/{$update->locale}-{$update->version}.tar.gz";
$cache_key = "core/{$update->locale}-{$update->version}.{$ext}";
$cache_file = $cache->has( $cache_key );

if ( $cache_file ) {
Expand All @@ -46,7 +48,7 @@ function download_package( $package ) {
} else {
// We need to use a temporary file because piping from cURL to tar is flaky
// on MinGW (and probably in other environments too).
$temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.tar.gz';
$temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.' . $ext;

$headers = array('Accept' => 'application/json');
$options = array(
Expand Down
12 changes: 10 additions & 2 deletions php/commands/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,18 @@ public function download( $args, $assoc_args ) {
$cache_key = "core/$locale-$version.tar.gz";
$cache_file = $cache->has($cache_key);

$bad_cache = false;
if ( $cache_file ) {
WP_CLI::log( "Using cached file '$cache_file'..." );
self::_extract( $cache_file, ABSPATH );
} else {
try{
self::_extract( $cache_file, ABSPATH );
} catch ( Exception $e ) {
WP_CLI::warning( "Extraction failed, downloading a new copy..." );
$bad_cache = true;
}
}

if ( ! $cache_file || $bad_cache ) {
// We need to use a temporary file because piping from cURL to tar is flaky
// on MinGW (and probably in other environments too).
$temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.tar.gz';
Expand Down