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
24 changes: 24 additions & 0 deletions features/core-download.feature
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,35 @@ Feature: Download WordPress

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

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.zip file should exist

Scenario: Core download with no-extract reports when the archive cannot be saved
Given an empty directory
And an empty cache
And a wordpress-4.5-de_DE.zip/placeholder.txt file:
"""
A directory in the way of the archive.
"""

When I try `wp core download --version=4.5 --locale=de_DE --no-extract`
Then STDERR should contain:
"""
Error: Couldn't copy WordPress archive to
"""
And the return code should be 1

When I run `wp core download --version=4.5 --locale=de_DE --no-extract --path=other`
And I try `wp core download --version=4.5 --locale=de_DE --no-extract`
Then STDERR should contain:
"""
Error: Couldn't copy WordPress archive to
"""
And the return code should be 1

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

Expand Down
13 changes: 10 additions & 3 deletions src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ public function download( $args, $assoc_args ) {
WP_CLI::warning( 'Extraction failed, downloading a new copy...' );
$bad_cache = true;
}
} else {
copy( $cache_file, $download_dir . basename( $cache_file ) );
} elseif ( ! copy( $cache_file, $download_dir . basename( $cache_file ) ) ) {
WP_CLI::error( "Couldn't copy WordPress archive to '{$download_dir}" . basename( $cache_file ) . "'." );
}
}

Expand Down Expand Up @@ -414,7 +414,14 @@ function () use ( $old_temp ) {
WP_CLI::error( "Couldn't extract WordPress archive. {$exception->getMessage()}" );
}
} else {
copy( $temp, $download_dir . basename( $temp ) );
// Name the archive like the cached one, rather than after the temporary file.
$archive_name = $from_url ? basename( (string) Utils\parse_url( $download_url, PHP_URL_PATH ) ) : "wordpress-{$version}-{$locale}.{$extension}";
if ( '' === $archive_name || '.' === $archive_name ) {
$archive_name = basename( $temp );
}
if ( ! copy( $temp, $download_dir . $archive_name ) ) {
WP_CLI::error( "Couldn't copy WordPress archive to '{$download_dir}{$archive_name}'." );
}
}

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