Merge remote-tracking branch 'upstream/4.3' into 4.3-4.4-2013-11-26-11-43-18
[civicrm-core.git] / CRM / Utils / File.php
index e25740c3889efaebd69938359ff3d11ec6645efa..bdea90483fd7767d1120b453a0bb7a07fc8de139 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -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,20 @@ HTACCESS;
     $result = array();
     while (!empty($todos)) {
       $subdir = array_shift($todos);
-      foreach (glob("$subdir/$pattern") as $match) {
-        if (!is_dir($match)) {
-          $result[] = $match;
+      $matches = glob("$subdir/$pattern");
+      if (is_array($matches)) {
+        foreach ($matches 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;
           }