Skip to content

Commit 84c524f

Browse files
swissspidyCopilot
andauthored
Update src/WP_CLI/Shell/REPL.php
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 875bcd4 commit 84c524f

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

src/WP_CLI/Shell/REPL.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,28 @@ private function get_recursive_mtime( $path ) {
218218
$dir_mtime = filemtime( $path );
219219
$mtime = false !== $dir_mtime ? $dir_mtime : 0;
220220

221-
$iterator = new \RecursiveIteratorIterator(
222-
new \RecursiveDirectoryIterator( $path, \RecursiveDirectoryIterator::SKIP_DOTS ),
223-
\RecursiveIteratorIterator::SELF_FIRST
224-
);
225-
226-
foreach ( $iterator as $file ) {
227-
/** @var \SplFileInfo $file */
228-
$file_mtime = $file->getMTime();
229-
if ( $file_mtime > $mtime ) {
230-
$mtime = $file_mtime;
221+
try {
222+
$iterator = new \RecursiveIteratorIterator(
223+
new \RecursiveDirectoryIterator( $path, \RecursiveDirectoryIterator::SKIP_DOTS ),
224+
\RecursiveIteratorIterator::SELF_FIRST
225+
);
226+
227+
foreach ( $iterator as $file ) {
228+
/** @var \SplFileInfo $file */
229+
$file_mtime = $file->getMTime();
230+
if ( $file_mtime > $mtime ) {
231+
$mtime = $file_mtime;
232+
}
231233
}
234+
} catch ( \UnexpectedValueException $e ) {
235+
// Handle unreadable directories/files gracefully.
236+
WP_CLI::warning(
237+
sprintf(
238+
'Could not read path "%s" while checking for changes: %s',
239+
$path,
240+
$e->getMessage()
241+
)
242+
);
232243
}
233244
}
234245

0 commit comments

Comments
 (0)