Skip to content

Commit 96cc645

Browse files
Merge branch 'master' into quote-paths
2 parents 91b037f + 64db9e3 commit 96cc645

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

features/find.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,12 @@ Feature: Find WordPress installs on the filesystem
152152
"""
153153
0
154154
"""
155+
156+
Scenario: Invalid path specified
157+
Given an empty directory
158+
159+
When I try `wp find foo`
160+
Then STDERR should be:
161+
"""
162+
Error: Invalid path specified.
163+
"""

src/Find_Command.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ class Find_Command {
141141
public function __invoke( $args, $assoc_args ) {
142142
list( $path ) = $args;
143143
$this->base_path = realpath( $path );
144+
if ( ! $this->base_path ) {
145+
WP_CLI::error( 'Invalid path specified.' );
146+
}
144147
$this->skip_ignored_paths = Utils\get_flag_value( $assoc_args, 'skip-ignored-paths' );
145148
$this->max_depth = Utils\get_flag_value( $assoc_args, 'max_depth', false );
146149
$this->verbose = Utils\get_flag_value( $assoc_args, 'verbose' );
@@ -195,8 +198,13 @@ private function recurse_directory( $path ) {
195198

196199
// Check all files and directories of this path to recurse
197200
// into subdirectories.
201+
try {
202+
$iterator = new RecursiveDirectoryIterator( $path, FilesystemIterator::SKIP_DOTS );
203+
} catch( Exception $e ) {
204+
$this->log( "Exception thrown '{$e->getMessage()}'. Skipping recursion into '{$path}'" );
205+
return;
206+
}
198207
$this->log( "Recusing into '{$path}'" );
199-
$iterator = new RecursiveDirectoryIterator( $path, FilesystemIterator::SKIP_DOTS );
200208
foreach( $iterator as $file_info ) {
201209
if ( $file_info->isDir() ) {
202210
$this->current_depth++;

0 commit comments

Comments
 (0)