Skip to content

Commit

Permalink
Removing unused function Folder::_tree(). Added exception handling in…
Browse files Browse the repository at this point in the history
… Folder::delete().
  • Loading branch information
ADmad committed Dec 21, 2011
1 parent 3890727 commit b84c9a1
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions lib/Cake/Utility/Folder.php
Expand Up @@ -459,20 +459,6 @@ public function tree($path = null, $exceptions = true, $type = null) {
return $files;
}

/**
* Private method to list directories and files in each directory
*
* @param string $path The Path to read.
* @param mixed $exceptions Array of files to exclude from the read that will be performed.
* @return void
*/
protected function _tree($path, $exceptions) {
$this->path = $path;
list($dirs, $files) = $this->read(false, $exceptions, true);
$this->_directories = array_merge($this->_directories, $dirs);
$this->_files = array_merge($this->_files, $files);
}

/**
* Create a directory structure recursively. Can be used to create
* deep path structures like `/foo/bar/baz/shoe/horn`
Expand Down Expand Up @@ -567,16 +553,22 @@ public function delete($path = null) {
}
$path = Folder::slashTerm($path);
if (is_dir($path)) {
$iterator = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) {
$filePath = $file->getPathname();
if ($file->isFile() || $file->isLink()) {
try {
$directory = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::CHILD_FIRST);
} catch (UnexpectedValueException $e) {
return false;
}

foreach ($iterator as $item) {
$filePath = $item->getPathname();
if ($item->isFile() || $item->isLink()) {
if (@unlink($filePath)) {
$this->_messages[] = __d('cake_dev', '%s removed', $filePath);
} else {
$this->_errors[] = __d('cake_dev', '%s NOT removed', $filePath);
}
} elseif ($file->isDir()) {
} elseif ($item->isDir()) {
if (@rmdir($filePath)) {
$this->_messages[] = __d('cake_dev', '%s removed', $filePath);
} else {
Expand Down

0 comments on commit b84c9a1

Please sign in to comment.