CRM-13108 - Fix warning in CRM_Utils_File::findFiles (from rubofvil)
[civicrm-core.git] / CRM / Utils / File.php
index f1917a171ae211fd3c9be2d874c0c3f48f082ca3..5d068bf18d4e6a1a1c2d295a5e56294e8256fd43 100644 (file)
@@ -516,7 +516,9 @@ HTACCESS;
   }
 
   /**
-   * Search directory tree for files which match a glob pattern
+   * Search directory tree for files which match a glob pattern.
+   *
+   * Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
    *
    * @param $dir string, base dir
    * @param $pattern string, glob pattern, eg "*.txt"
@@ -527,16 +529,19 @@ HTACCESS;
     $result = array();
     while (!empty($todos)) {
       $subdir = array_shift($todos);
-      foreach (glob("$subdir/$pattern") as $match) {
-        if (!is_dir($match)) {
-          $result[] = $match;
+      if (is_array(glob("$subdir/$pattern"))) {
+        foreach (glob("$subdir/$pattern") as $match) {
+          if (!is_dir($match)) {
+            $result[] = $match;
+          }
         }
       }
       $dh = opendir($subdir);
       if ($dh) {
         while (FALSE !== ($entry = readdir($dh))) {
           $path = $subdir . DIRECTORY_SEPARATOR . $entry;
-          if ($entry == '.' || $entry == '..' || $entry == '.svn') {
+          if ($entry{0} == '.') {
+            // ignore
           } elseif (is_dir($path)) {
             $todos[] = $path;
           }