From 687c5cea08db3e25072d7b80439ec0acd2197a56 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Thu, 18 Dec 2014 08:51:54 +0100 Subject: [PATCH] enhance findDirs() to avoid exceptions on unreadable directory Signed-off-by: Michael Kaufmann (d00p) --- lib/functions/filedir/function.findDirs.php | 27 ++++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/functions/filedir/function.findDirs.php b/lib/functions/filedir/function.findDirs.php index 45aecca3..8d63d48b 100644 --- a/lib/functions/filedir/function.findDirs.php +++ b/lib/functions/filedir/function.findDirs.php @@ -36,18 +36,27 @@ function findDirs($path, $uid, $gid) { // valid directory? if (is_dir($path)) { - // create RecursiveIteratorIterator - $its = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); - - // check every file - foreach ($its as $fullFileName => $it) { - if ($it->isDir() - && (fileowner($fullFileName) == $uid || filegroup($fullFileName) == $gid) - ) { - $_fileList[] = makeCorrectDir(dirname($fullFileName)); + try { + // create RecursiveIteratorIterator + $its = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); + // we can limit the recursion-depth, but will it be helpful or + // will people start asking "why do I only see 2 subdirectories, i want to use /a/b/c" + // let's keep this in mind and see whether it will be useful + // @TODO + // $its->setMaxDepth(2); + + // check every file + foreach ($its as $fullFileName => $it) { + if ($it->isDir() && (fileowner($fullFileName) == $uid || filegroup($fullFileName) == $gid)) { + $_fileList[] = makeCorrectDir(dirname($fullFileName)); + } } + } catch (UnexpectedValueException $e) { + // this is thrown if the directory is not found or not readble etc. + // just ignore and keep going } } return array_unique($_fileList); + }