class FSFileIterator implements Iterator {
/** @var RecursiveIteratorIterator */
protected $iter;
+ protected $suffixStart; // integer
/**
* Get an FSFileIterator from a file system directory
* @param $dir string
*/
public function __construct( $dir ) {
+ $this->suffixStart = strlen( realpath( $dir ) ) + 1; // size of "path/to/dir/"
try {
$this->iter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir ) );
} catch ( UnexpectedValueException $e ) {
}
public function current() {
- return $this->iter->current();
+ // Return only the relative path and normalize slashes to FileBackend-style
+ return str_replace( '\\', '/', substr( $this->iter->current(), $this->suffixStart ) );
}
public function key() {
/**
* If the iterator for this container shard is out of items,
* then move on to the next container that has items.
+ * If there are none, then it advances to the last container.
*/
protected function nextShardIteratorIfNotValid() {
while ( !$this->valid() ) {
"subdir1/test1.txt",
"subdir1/test2.txt",
"subdir2/test3.txt",
- "subdir2/test1.txt",
+ "subdir2/test4.txt",
"subdir2/subdir/test1.txt",
"subdir2/subdir/test2.txt",
"subdir2/subdir/test3.txt",
"subdir2/subdir/sub/test0.txt",
"subdir2/subdir/sub/120-px-file.txt",
);
- $expected = sort( $expected );
+ sort( $expected );
// Actual listing (no trailing slash)
$list = array();
foreach ( $iter as $file ) {
$list[] = $file;
}
+ sort( $list );
- $this->assertEquals( $expected, sort( $list ), "Correct file listing." );
+ $this->assertEquals( $expected, $list, "Correct file listing." );
// Actual listing (with trailing slash)
$list = array();
foreach ( $iter as $file ) {
$list[] = $file;
}
+ sort( $list );
- $this->assertEquals( $expected, sort( $list ), "Correct file listing." );
+ $this->assertEquals( $expected, $list, "Correct file listing." );
foreach ( $files as $file ) {
$this->backend->doOperation( array( 'op' => 'delete', 'src' => "$base/$file" ) );