Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure cache directories are accessible #5068

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions features/cli-cache.feature
Expand Up @@ -26,6 +26,18 @@ Feature: CLI Cache
wordpress-4.9-en_US.tar.gz
"""

Scenario: Using a null device disables the cache without throwing an error
Given an empty directory
And a env-var.php file:
"""
<?php
putenv( 'WP_CLI_CACHE_DIR=/dev/null' );
"""

When I run `wp --require=env-var.php core download --path=/tmp/wp-core --version=4.9 --force`
Then STDERR should be empty


Scenario: Remove all but newest files from cache directory
Given an empty cache
And a file-a-12345.tmp cache file:
Expand Down
5 changes: 5 additions & 0 deletions php/WP_CLI/FileCache.php
Expand Up @@ -314,6 +314,11 @@ public function prune() {
*/
protected function ensure_dir_exists( $dir ) {
if ( ! is_dir( $dir ) ) {
// Disable the cache if a null device like /dev/null is being used.
if ( preg_match( '{(^|[\\\\/])(\$null|nul|NUL|/dev/null)([\\\\/]|$)}', $dir ) ) {
killua99 marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
killua99 marked this conversation as resolved.
Show resolved Hide resolved

if ( ! @mkdir( $dir, 0777, true ) ) { // @codingStandardsIgnoreLine
$error = error_get_last();
\WP_CLI::warning( sprintf( "Failed to create directory '%s': %s.", $dir, $error['message'] ) );
Expand Down