From 64997718e0e98a3afe00b4d956b8dcf89dc3479c Mon Sep 17 00:00:00 2001 From: phpnut Date: Tue, 12 Dec 2006 22:11:24 +0000 Subject: [PATCH] Merging fixes from 1.1.x.x Folder class to 1.2.x.x git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4096 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/folder.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/cake/libs/folder.php b/cake/libs/folder.php index 19a52bcbf..0154727a1 100644 --- a/cake/libs/folder.php +++ b/cake/libs/folder.php @@ -87,7 +87,7 @@ class Folder extends Object{ function cd($desiredPath) { $desiredPath = realpath($desiredPath); $newPath = $this->isAbsolute($desiredPath) ? $desiredPath : $this->addPathElement($this->path, $desiredPath); - $isDir = is_dir($newPath) ? $this->path = $newPath : false; + $isDir = (is_dir($newPath) && file_exists($newPath)) ? $this->path = $newPath : false; return $isDir; } /** @@ -99,10 +99,9 @@ class Folder extends Object{ * @return array */ function ls($sort = true, $noDotFiles = false) { + $dirs = $files = array(); $dir = opendir($this->path); if ($dir) { - $dirs = $files = array(); - while(false !== ($n = readdir($dir))) { if ((!preg_match('#^\.+$#', $n) && $noDotFiles == false) || ($noDotFiles == true && !preg_match('#^\.(.*)$#', $n))) { if (is_dir($this->addPathElement($this->path, $n))) { @@ -118,11 +117,8 @@ class Folder extends Object{ sort ($files); } closedir ($dir); - $array = array($dirs,$files); - return $array; - } else { - return false; - } + } + return array($dirs,$files); } /** * Returns an array of all matching files in current directory. @@ -137,7 +133,7 @@ class Folder extends Object{ return array(); } - list($dirs, $files)=$data; + list($dirs, $files) = $data; $found = array(); foreach($files as $file) { @@ -168,6 +164,7 @@ class Folder extends Object{ */ function _findRecursive($pattern) { list($dirs, $files) = $this->ls(); + $found = array(); foreach($files as $file) { if (preg_match("/^{$pattern}$/i", $file)) { @@ -175,7 +172,6 @@ class Folder extends Object{ } } $start = $this->path; - foreach($dirs as $dir) { $this->cd($this->addPathElement($start, $dir)); $found = array_merge($found, $this->findRecursive($pattern));