From 7a009541cea270657ee49bd2877c4ea00c17f63d Mon Sep 17 00:00:00 2001 From: Matthew Barbour Date: Wed, 24 Jun 2020 09:02:14 -0500 Subject: [PATCH] Added more explicit failure handling to list_files --- core/polyfills.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/polyfills.php b/core/polyfills.php index 8199549e..8f6f62ff 100644 --- a/core/polyfills.php +++ b/core/polyfills.php @@ -127,10 +127,16 @@ function list_files(string $base, string $_sub_dir=""): array $files = []; $dir = opendir("$base/$_sub_dir"); - while ($f = readdir($dir)) { - $files[] = $f; + if($dir===false) { + throw new SCoreException("Unable to open directory $base/$_sub_dir"); + } + try { + while ($f = readdir($dir)) { + $files[] = $f; + } + } finally { + closedir($dir); } - closedir($dir); sort($files); foreach ($files as $filename) {