r110159 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110158‎ | r110159 | r110160 >
Date:20:12, 27 January 2012
Author:aaron
Status:ok
Tags:
Comment:
* Reverted r108194 to support PHP < 5.3. These should already be the default iterator settings.
* Also made the iterator keys (e.g. in foreach) more consistent by being integers as the other backend iterators do.
Modified paths:
  • /trunk/phase3/includes/filerepo/backend/FSFileBackend.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/backend/FSFileBackend.php
@@ -540,6 +540,7 @@
541541 /** @var RecursiveIteratorIterator */
542542 protected $iter;
543543 protected $suffixStart; // integer
 544+ protected $pos = 0; // integer
544545
545546 /**
546547 * @param $dir string file system directory
@@ -548,9 +549,8 @@
549550 $dir = realpath( $dir ); // normalize
550551 $this->suffixStart = strlen( $dir ) + 1; // size of "path/to/dir/"
551552 try {
552 - $flags = FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS;
553 - $this->iter = new RecursiveIteratorIterator(
554 - new RecursiveDirectoryIterator( $dir, $flags ) );
 553+ # Get an iterator that will return leaf nodes (non-directories)
 554+ $this->iter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir ) );
555555 } catch ( UnexpectedValueException $e ) {
556556 $this->iter = null; // bad permissions? deleted?
557557 }
@@ -564,7 +564,7 @@
565565 }
566566
567567 public function key() {
568 - return $this->iter->key();
 568+ return $this->pos;
569569 }
570570
571571 public function next() {
@@ -573,9 +573,11 @@
574574 } catch ( UnexpectedValueException $e ) {
575575 $this->iter = null;
576576 }
 577+ ++$this->pos;
577578 }
578579
579580 public function rewind() {
 581+ $this->pos = 0;
580582 try {
581583 $this->iter->rewind();
582584 } catch ( UnexpectedValueException $e ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r110163Follow-up r110159: set the FilesystemIterator flags when that class is availa...aaron20:35, 27 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r108194r108192: Explicitly set flags for RecursiveDirectoryIterator constructoraaron06:35, 6 January 2012

Status & tagging log