Skip to content

Commit

Permalink
Merge pull request #213 from wp-cli/fix/no-extract-file-location
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera authored Oct 12, 2022
2 parents 30dfbe5 + bce1425 commit ac58bb1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
41 changes: 39 additions & 2 deletions features/core-download.feature
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,51 @@ Feature: Download WordPress
And the wp-content/plugins directory should not exist
And the wp-content/themes directory should not exist

Scenario: Core download without extract parameter should unzip the download file
Given an empty directory

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

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

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

Scenario: Core download with extract parameter should unzip the download file (already cached)
Given an empty directory

When I run `wp core download --version=4.5 --locale=de_DE --extract`
And I run `rm -rf *`
And I run `wp core download --version=4.5 --locale=de_DE --extract`
Then the wp-content directory should exist
And the wordpress-4.5-de_DE.tar.gz file should not exist

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

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

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

When I run `wp core download --version=4.5 --locale=de_DE --no-extract`
And I run `rm -rf wordpress-4.5-de_DE.tar.gz`
And I run `wp core download --version=4.5 --locale=de_DE --no-extract`
Then the wp-content directory should not exist
And the wordpress-4.5-de_DE.tar.gz file should exist

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

When I try `wp core download --skip-content --no-extract`
Then STDERR should contain:
"""
Error: Cannot use both --skip-content and --no-extract at the same time.
"""
And the return code should be 1
13 changes: 10 additions & 3 deletions src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ public function download( $args, $assoc_args ) {
$locale = (string) Utils\get_flag_value( $assoc_args, 'locale', 'en_US' );
$skip_content = (bool) Utils\get_flag_value( $assoc_args, 'skip-content', false );
$insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false );
$extract = (bool) Utils\get_flag_value( $assoc_args, 'extract', true );

if ( $skip_content && ! $extract ) {
WP_CLI::error( 'Cannot use both --skip-content and --no-extract at the same time.' );
}

$download_url = array_shift( $args );
$from_url = ! empty( $download_url );
Expand Down Expand Up @@ -223,7 +228,7 @@ public function download( $args, $assoc_args ) {
$extension = 'tar.gz';
if ( 'zip' === $path_parts['extension'] ) {
$extension = 'zip';
if ( ! class_exists( 'ZipArchive' ) ) {
if ( $extract && ! class_exists( 'ZipArchive' ) ) {
WP_CLI::error( 'Extracting a zip file requires ZipArchive.' );
}
}
Expand All @@ -241,19 +246,19 @@ public function download( $args, $assoc_args ) {
}

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

if ( $cache_file ) {
WP_CLI::log( "Using cached file '{$cache_file}'..." );
$skip_content_cache_file = $skip_content ? self::strip_content_dir( $cache_file ) : null;
if ( $extract ) {
try {
Extractor::extract( $skip_content_cache_file ?: $cache_file, $download_dir );

} catch ( Exception $exception ) {
WP_CLI::warning( 'Extraction failed, downloading a new copy...' );
$bad_cache = true;
}
} else {
copy( $cache_file, $download_dir . basename( $cache_file ) );
}
}

Expand Down Expand Up @@ -309,6 +314,8 @@ function () use ( $temp ) {
} catch ( Exception $exception ) {
WP_CLI::error( "Couldn't extract WordPress archive. {$exception->getMessage()}" );
}
} else {
copy( $temp, $download_dir . basename( $temp ) );
}

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

0 comments on commit ac58bb1

Please sign in to comment.