#935036 by bfroehle, dww, int: Exclude '.' and '..' when recursing through directories in update module.
parent
8fc5911c36
commit
66ffb5f7e8
|
@ -208,7 +208,7 @@ abstract class FileTransfer {
|
||||||
$destination = $destination . '/' . basename($source);
|
$destination = $destination . '/' . basename($source);
|
||||||
}
|
}
|
||||||
$this->createDirectory($destination);
|
$this->createDirectory($destination);
|
||||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST) as $filename => $file) {
|
foreach (new RecursiveIteratorIterator(new SkipDotsRecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST) as $filename => $file) {
|
||||||
$relative_path = substr($filename, strlen($source));
|
$relative_path = substr($filename, strlen($source));
|
||||||
if ($file->isDir()) {
|
if ($file->isDir()) {
|
||||||
$this->createDirectory($destination . $relative_path);
|
$this->createDirectory($destination . $relative_path);
|
||||||
|
@ -345,3 +345,31 @@ interface FileTransferChmodInterface {
|
||||||
*/
|
*/
|
||||||
function chmodJailed($path, $mode, $recursive);
|
function chmodJailed($path, $mode, $recursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an interface for iterating recursively over filesystem directories.
|
||||||
|
*
|
||||||
|
* Manually skips '.' and '..' directories, since no existing method is
|
||||||
|
* available in PHP 5.2.
|
||||||
|
*
|
||||||
|
* @todo Depreciate in favor of RecursiveDirectoryIterator::SKIP_DOTS once PHP
|
||||||
|
* 5.3 or later is required.
|
||||||
|
*/
|
||||||
|
class SkipDotsRecursiveDirectoryIterator extends RecursiveDirectoryIterator {
|
||||||
|
/**
|
||||||
|
* Constructs a SkipDotsRecursiveDirectoryIterator
|
||||||
|
*
|
||||||
|
* @param $path
|
||||||
|
* The path of the directory to be iterated over.
|
||||||
|
*/
|
||||||
|
function __construct($path) {
|
||||||
|
parent::__construct($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
function next() {
|
||||||
|
parent::next();
|
||||||
|
while ($this->isDot()) {
|
||||||
|
parent::next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ class FileTransferLocal extends FileTransfer implements FileTransferChmodInterfa
|
||||||
// Programmer error assertion, not something we expect users to see.
|
// 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));
|
throw new FileTransferException('removeDirectoryJailed() called with a path (%directory) that is not a directory.', NULL, array('%directory' => $directory));
|
||||||
}
|
}
|
||||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST) as $filename => $file) {
|
foreach (new RecursiveIteratorIterator(new SkipDotsRecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST) as $filename => $file) {
|
||||||
if ($file->isDir()) {
|
if ($file->isDir()) {
|
||||||
if (@!drupal_rmdir($filename)) {
|
if (@!drupal_rmdir($filename)) {
|
||||||
throw new FileTransferException('Cannot remove directory %directory.', NULL, array('%directory' => $filename));
|
throw new FileTransferException('Cannot remove directory %directory.', NULL, array('%directory' => $filename));
|
||||||
|
@ -64,7 +64,7 @@ class FileTransferLocal extends FileTransfer implements FileTransferChmodInterfa
|
||||||
|
|
||||||
public function chmodJailed($path, $mode, $recursive) {
|
public function chmodJailed($path, $mode, $recursive) {
|
||||||
if ($recursive && is_dir($path)) {
|
if ($recursive && is_dir($path)) {
|
||||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST) as $filename => $file) {
|
foreach (new RecursiveIteratorIterator(new SkipDotsRecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST) as $filename => $file) {
|
||||||
if (@!chmod($filename, $mode)) {
|
if (@!chmod($filename, $mode)) {
|
||||||
throw new FileTransferException('Cannot chmod %path.', NULL, array('%path' => $filename));
|
throw new FileTransferException('Cannot chmod %path.', NULL, array('%path' => $filename));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue