diff --git a/features/core-download.feature b/features/core-download.feature index 154eb897..1242fc80 100644 --- a/features/core-download.feature +++ b/features/core-download.feature @@ -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 diff --git a/src/Core_Command.php b/src/Core_Command.php index 33d0bc04..81eebfc7 100644 --- a/src/Core_Command.php +++ b/src/Core_Command.php @@ -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 ) . "'." ); } } @@ -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