diff -u includes/filetransfer/local.inc includes/filetransfer/local.inc --- includes/filetransfer/local.inc 25 Oct 2009 10:28:45 -0000 +++ includes/filetransfer/local.inc 26 Oct 2009 05:12:25 -0000 @@ -31,23 +31,18 @@ // Programmer error assertion, not something we expect users to see. throw new FileTransferException('removeDirectoryJailed() called with a path (%directory) that is not a directory.', NULL, array('%directory' => $directory)); } - $dir = dir($directory); - while (($entry = $dir->read()) !== FALSE) { - if ($entry == '.' || $entry == '..') { - continue; - } - $entry_path = $directory . '/' . $entry; - if (is_dir($entry_path)) { - $this->removeDirectoryJailed($entry_path); + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST) as $filename => $file) { + if ($file->isDir()) { + if (@!rmdir($filename)) { + throw new FileTransferException('Cannot remove directory %directory.', NULL, array('%directory' => $filename)); + } } - else { - if (@!unlink($entry_path)) { - throw new FileTransferException('Cannot remove file %file.', NULL, array('%file' => $entry_path)); + elseif ($file->isFile()) { + if (@!unlink($filename)) { + throw new FileTransferException('Cannot remove file %file.', NULL, array('%file' => $filename)); } - } } - $dir->close(); if (@!rmdir($directory)) { throw new FileTransferException('Cannot remove directory %directory.', NULL, array('%directory' => $directory)); } @@ -68,19 +63,15 @@ } public function chmodJailed($path, $mode, $recursive) { - if (@!chmod($path, $mode)) { - throw new FileTransferException('Cannot chmod %path.', NULL, array('%path' => $path)); - } if ($recursive && is_dir($path)) { - $dir = dir($path); - while (($entry = $dir->read()) !== FALSE) { - if ($entry == '.' || $entry == '..') { - continue; + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST) as $filename => $file) { + if (@!chmod($filename, $mode)) { + throw new FileTransferException('Cannot chmod %path.', NULL, array('%path' => $filename)); } - $entry_path = $path . '/' . $entry; - $this->chmodJailed($entry_path, $mode, $recursive); } - $dir->close(); + } + elseif (@!chmod($path, $mode)) { + throw new FileTransferException('Cannot chmod %path.', NULL, array('%path' => $path)); } } }