Skip to content

Commit ac58bb1

Browse files
authored
Merge pull request #213 from wp-cli/fix/no-extract-file-location
2 parents 30dfbe5 + bce1425 commit ac58bb1

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

features/core-download.feature

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,51 @@ Feature: Download WordPress
396396
And the wp-content/plugins directory should not exist
397397
And the wp-content/themes directory should not exist
398398

399+
Scenario: Core download without extract parameter should unzip the download file
400+
Given an empty directory
401+
402+
When I run `wp core download --version=4.5 --locale=de_DE`
403+
Then the wp-content directory should exist
404+
And the wordpress-4.5-de_DE.tar.gz file should not exist
405+
399406
Scenario: Core download with extract parameter should unzip the download file
400407
Given an empty directory
401408

402-
When I run `wp core download --extract`
409+
When I run `wp core download --version=4.5 --locale=de_DE --extract`
403410
Then the wp-content directory should exist
411+
And the wordpress-4.5-de_DE.tar.gz file should not exist
412+
413+
Scenario: Core download with extract parameter should unzip the download file (already cached)
414+
Given an empty directory
415+
416+
When I run `wp core download --version=4.5 --locale=de_DE --extract`
417+
And I run `rm -rf *`
418+
And I run `wp core download --version=4.5 --locale=de_DE --extract`
419+
Then the wp-content directory should exist
420+
And the wordpress-4.5-de_DE.tar.gz file should not exist
404421

405422
Scenario: Core download with no-extract should not unzip the download file
406423
Given an empty directory
407424

408-
When I run `wp core download --no-extract`
425+
When I run `wp core download --version=4.5 --locale=de_DE --no-extract`
426+
Then the wp-content directory should not exist
427+
And the wordpress-4.5-de_DE.tar.gz file should exist
428+
429+
Scenario: Core download with no-extract should not unzip the download file (already cached)
430+
Given an empty directory
431+
432+
When I run `wp core download --version=4.5 --locale=de_DE --no-extract`
433+
And I run `rm -rf wordpress-4.5-de_DE.tar.gz`
434+
And I run `wp core download --version=4.5 --locale=de_DE --no-extract`
409435
Then the wp-content directory should not exist
436+
And the wordpress-4.5-de_DE.tar.gz file should exist
437+
438+
Scenario: Error when using both --skip-content and --no-extract
439+
Given an empty directory
440+
441+
When I try `wp core download --skip-content --no-extract`
442+
Then STDERR should contain:
443+
"""
444+
Error: Cannot use both --skip-content and --no-extract at the same time.
445+
"""
446+
And the return code should be 1

src/Core_Command.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ public function download( $args, $assoc_args ) {
162162
$locale = (string) Utils\get_flag_value( $assoc_args, 'locale', 'en_US' );
163163
$skip_content = (bool) Utils\get_flag_value( $assoc_args, 'skip-content', false );
164164
$insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false );
165+
$extract = (bool) Utils\get_flag_value( $assoc_args, 'extract', true );
166+
167+
if ( $skip_content && ! $extract ) {
168+
WP_CLI::error( 'Cannot use both --skip-content and --no-extract at the same time.' );
169+
}
165170

166171
$download_url = array_shift( $args );
167172
$from_url = ! empty( $download_url );
@@ -223,7 +228,7 @@ public function download( $args, $assoc_args ) {
223228
$extension = 'tar.gz';
224229
if ( 'zip' === $path_parts['extension'] ) {
225230
$extension = 'zip';
226-
if ( ! class_exists( 'ZipArchive' ) ) {
231+
if ( $extract && ! class_exists( 'ZipArchive' ) ) {
227232
WP_CLI::error( 'Extracting a zip file requires ZipArchive.' );
228233
}
229234
}
@@ -241,19 +246,19 @@ public function download( $args, $assoc_args ) {
241246
}
242247

243248
$bad_cache = false;
244-
$extract = (bool) Utils\get_flag_value( $assoc_args, 'extract', true );
245249

246250
if ( $cache_file ) {
247251
WP_CLI::log( "Using cached file '{$cache_file}'..." );
248252
$skip_content_cache_file = $skip_content ? self::strip_content_dir( $cache_file ) : null;
249253
if ( $extract ) {
250254
try {
251255
Extractor::extract( $skip_content_cache_file ?: $cache_file, $download_dir );
252-
253256
} catch ( Exception $exception ) {
254257
WP_CLI::warning( 'Extraction failed, downloading a new copy...' );
255258
$bad_cache = true;
256259
}
260+
} else {
261+
copy( $cache_file, $download_dir . basename( $cache_file ) );
257262
}
258263
}
259264

@@ -309,6 +314,8 @@ function () use ( $temp ) {
309314
} catch ( Exception $exception ) {
310315
WP_CLI::error( "Couldn't extract WordPress archive. {$exception->getMessage()}" );
311316
}
317+
} else {
318+
copy( $temp, $download_dir . basename( $temp ) );
312319
}
313320

314321
// Do not use the cache for nightly builds or for downloaded URLs

0 commit comments

Comments
 (0)