Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removing unused function Folder::_tree(). Added exception handling in…

… Folder::delete().
  • Loading branch information...
commit b84c9a1aaac85eb9669bcee8c4bd10e3a432c161 1 parent 3890727
@ADmad ADmad authored
Showing with 11 additions and 19 deletions.
  1. +11 −19 lib/Cake/Utility/Folder.php
View
30 lib/Cake/Utility/Folder.php
@@ -460,20 +460,6 @@ public function tree($path = null, $exceptions = true, $type = null) {
}
/**
- * 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`
*
@@ -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 {
Please sign in to comment.
Something went wrong with that request. Please try again.