From: aneganov Date: Thu, 8 Jan 2015 22:31:03 +0000 (+0300) Subject: CRM-15799 - System crash on attempt to upgrade from 4.5.4 to 4.5.5 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5e7670b1c02317402f2cb11fd02261c04fde9a07;p=civicrm-core.git CRM-15799 - System crash on attempt to upgrade from 4.5.4 to 4.5.5 ---------------------------------------- * CRM-15799: System crash on attempt to upgrade from 4.5.4 to 4.5.5 https://issues.civicrm.org/jira/browse/CRM-15799 --- diff --git a/CRM/Utils/File.php b/CRM/Utils/File.php index 42ef38472b..255a0c118f 100644 --- a/CRM/Utils/File.php +++ b/CRM/Utils/File.php @@ -146,8 +146,8 @@ class CRM_Utils_File { throw new Exception("Overly broad deletion"); } - if ($sourcedir = @opendir($target)) { - while (FALSE !== ($sibling = readdir($sourcedir))) { + if ($dh = @opendir($target)) { + while (FALSE !== ($sibling = readdir($dh))) { if (!in_array($sibling, $exceptions)) { $object = $target . DIRECTORY_SEPARATOR . $sibling; @@ -161,7 +161,7 @@ class CRM_Utils_File { } } } - closedir($sourcedir); + closedir($dh); if ($rmdir) { if (rmdir($target)) { @@ -182,19 +182,20 @@ class CRM_Utils_File { * @param $destination */ static function copyDir($source, $destination) { - $dir = opendir($source); - @mkdir($destination); - while (FALSE !== ($file = readdir($dir))) { - if (($file != '.') && ($file != '..')) { - if (is_dir($source . DIRECTORY_SEPARATOR . $file)) { - CRM_Utils_File::copyDir($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file); - } - else { - copy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file); + if ($dh = opendir($source)) { + @mkdir($destination); + while (FALSE !== ($file = readdir($dh))) { + if (($file != '.') && ($file != '..')) { + if (is_dir($source . DIRECTORY_SEPARATOR . $file)) { + CRM_Utils_File::copyDir($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file); + } + else { + copy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file); + } } } + closedir($dh); } - closedir($dir); } /** @@ -400,14 +401,15 @@ class CRM_Utils_File { */ static function getFilesByExtension($path, $ext) { $path = self::addTrailingSlash($path); - $dh = opendir($path); $files = array(); - while (FALSE !== ($elem = readdir($dh))) { - if (substr($elem, -(strlen($ext) + 1)) == '.' . $ext) { - $files[] .= $path . $elem; + if ($dh = opendir($path)) { + while (FALSE !== ($elem = readdir($dh))) { + if (substr($elem, -(strlen($ext) + 1)) == '.' . $ext) { + $files[] .= $path . $elem; + } } + closedir($dh); } - closedir($dh); return $files; } @@ -618,8 +620,7 @@ HTACCESS; } } } - $dh = opendir($subdir); - if ($dh) { + if ($dh = opendir($subdir)) { while (FALSE !== ($entry = readdir($dh))) { $path = $subdir . DIRECTORY_SEPARATOR . $entry; if ($entry{0} == '.') {