Merge "(bug 20189) Added 'Show/hide selected revisions' button and checkboxes to...
[lhc/web/wiklou.git] / includes / filerepo / backend / FSFileBackend.php
1 <?php
2 /**
3 * File system based backend.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup FileBackend
22 * @author Aaron Schulz
23 */
24
25 /**
26 * @brief Class for a file system (FS) based file backend.
27 *
28 * All "containers" each map to a directory under the backend's base directory.
29 * For backwards-compatibility, some container paths can be set to custom paths.
30 * The wiki ID will not be used in any custom paths, so this should be avoided.
31 *
32 * Having directories with thousands of files will diminish performance.
33 * Sharding can be accomplished by using FileRepo-style hash paths.
34 *
35 * Status messages should avoid mentioning the internal FS paths.
36 * PHP warnings are assumed to be logged rather than output.
37 *
38 * @ingroup FileBackend
39 * @since 1.19
40 */
41 class FSFileBackend extends FileBackendStore {
42 protected $basePath; // string; directory holding the container directories
43 /** @var Array Map of container names to root paths */
44 protected $containerPaths = array(); // for custom container paths
45 protected $fileMode; // integer; file permission mode
46
47 protected $hadWarningErrors = array();
48
49 /**
50 * @see FileBackendStore::__construct()
51 * Additional $config params include:
52 * basePath : File system directory that holds containers.
53 * containerPaths : Map of container names to custom file system directories.
54 * This should only be used for backwards-compatibility.
55 * fileMode : Octal UNIX file permissions to use on files stored.
56 */
57 public function __construct( array $config ) {
58 parent::__construct( $config );
59
60 // Remove any possible trailing slash from directories
61 if ( isset( $config['basePath'] ) ) {
62 $this->basePath = rtrim( $config['basePath'], '/' ); // remove trailing slash
63 } else {
64 $this->basePath = null; // none; containers must have explicit paths
65 }
66
67 if ( isset( $config['containerPaths'] ) ) {
68 $this->containerPaths = (array)$config['containerPaths'];
69 foreach ( $this->containerPaths as &$path ) {
70 $path = rtrim( $path, '/' ); // remove trailing slash
71 }
72 }
73
74 $this->fileMode = isset( $config['fileMode'] )
75 ? $config['fileMode']
76 : 0644;
77 }
78
79 /**
80 * @see FileBackendStore::resolveContainerPath()
81 * @return null|string
82 */
83 protected function resolveContainerPath( $container, $relStoragePath ) {
84 // Check that container has a root directory
85 if ( isset( $this->containerPaths[$container] ) || isset( $this->basePath ) ) {
86 // Check for sane relative paths (assume the base paths are OK)
87 if ( $this->isLegalRelPath( $relStoragePath ) ) {
88 return $relStoragePath;
89 }
90 }
91 return null;
92 }
93
94 /**
95 * Sanity check a relative file system path for validity
96 *
97 * @param $path string Normalized relative path
98 * @return bool
99 */
100 protected function isLegalRelPath( $path ) {
101 // Check for file names longer than 255 chars
102 if ( preg_match( '![^/]{256}!', $path ) ) { // ext3/NTFS
103 return false;
104 }
105 if ( wfIsWindows() ) { // NTFS
106 return !preg_match( '![:*?"<>|]!', $path );
107 } else {
108 return true;
109 }
110 }
111
112 /**
113 * Given the short (unresolved) and full (resolved) name of
114 * a container, return the file system path of the container.
115 *
116 * @param $shortCont string
117 * @param $fullCont string
118 * @return string|null
119 */
120 protected function containerFSRoot( $shortCont, $fullCont ) {
121 if ( isset( $this->containerPaths[$shortCont] ) ) {
122 return $this->containerPaths[$shortCont];
123 } elseif ( isset( $this->basePath ) ) {
124 return "{$this->basePath}/{$fullCont}";
125 }
126 return null; // no container base path defined
127 }
128
129 /**
130 * Get the absolute file system path for a storage path
131 *
132 * @param $storagePath string Storage path
133 * @return string|null
134 */
135 protected function resolveToFSPath( $storagePath ) {
136 list( $fullCont, $relPath ) = $this->resolveStoragePathReal( $storagePath );
137 if ( $relPath === null ) {
138 return null; // invalid
139 }
140 list( $b, $shortCont, $r ) = FileBackend::splitStoragePath( $storagePath );
141 $fsPath = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
142 if ( $relPath != '' ) {
143 $fsPath .= "/{$relPath}";
144 }
145 return $fsPath;
146 }
147
148 /**
149 * @see FileBackendStore::isPathUsableInternal()
150 * @return bool
151 */
152 public function isPathUsableInternal( $storagePath ) {
153 $fsPath = $this->resolveToFSPath( $storagePath );
154 if ( $fsPath === null ) {
155 return false; // invalid
156 }
157 $parentDir = dirname( $fsPath );
158
159 if ( file_exists( $fsPath ) ) {
160 $ok = is_file( $fsPath ) && is_writable( $fsPath );
161 } else {
162 $ok = is_dir( $parentDir ) && is_writable( $parentDir );
163 }
164
165 return $ok;
166 }
167
168 /**
169 * @see FileBackendStore::doStoreInternal()
170 * @return Status
171 */
172 protected function doStoreInternal( array $params ) {
173 $status = Status::newGood();
174
175 $dest = $this->resolveToFSPath( $params['dst'] );
176 if ( $dest === null ) {
177 $status->fatal( 'backend-fail-invalidpath', $params['dst'] );
178 return $status;
179 }
180
181 if ( file_exists( $dest ) ) {
182 if ( !empty( $params['overwrite'] ) ) {
183 $ok = unlink( $dest );
184 if ( !$ok ) {
185 $status->fatal( 'backend-fail-delete', $params['dst'] );
186 return $status;
187 }
188 } else {
189 $status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
190 return $status;
191 }
192 }
193
194 $ok = copy( $params['src'], $dest );
195 // In some cases (at least over NFS), copy() returns true when it fails.
196 if ( !$ok || ( filesize( $params['src'] ) !== filesize( $dest ) ) ) {
197 if ( $ok ) { // PHP bug
198 unlink( $dest ); // remove broken file
199 trigger_error( __METHOD__ . ": copy() failed but returned true." );
200 }
201 $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] );
202 return $status;
203 }
204
205 $this->chmod( $dest );
206
207 return $status;
208 }
209
210 /**
211 * @see FileBackendStore::doCopyInternal()
212 * @return Status
213 */
214 protected function doCopyInternal( array $params ) {
215 $status = Status::newGood();
216
217 $source = $this->resolveToFSPath( $params['src'] );
218 if ( $source === null ) {
219 $status->fatal( 'backend-fail-invalidpath', $params['src'] );
220 return $status;
221 }
222
223 $dest = $this->resolveToFSPath( $params['dst'] );
224 if ( $dest === null ) {
225 $status->fatal( 'backend-fail-invalidpath', $params['dst'] );
226 return $status;
227 }
228
229 if ( file_exists( $dest ) ) {
230 if ( !empty( $params['overwrite'] ) ) {
231 $ok = unlink( $dest );
232 if ( !$ok ) {
233 $status->fatal( 'backend-fail-delete', $params['dst'] );
234 return $status;
235 }
236 } else {
237 $status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
238 return $status;
239 }
240 }
241
242 $ok = copy( $source, $dest );
243 // In some cases (at least over NFS), copy() returns true when it fails.
244 if ( !$ok || ( filesize( $source ) !== filesize( $dest ) ) ) {
245 if ( $ok ) { // PHP bug
246 unlink( $dest ); // remove broken file
247 trigger_error( __METHOD__ . ": copy() failed but returned true." );
248 }
249 $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
250 return $status;
251 }
252
253 $this->chmod( $dest );
254
255 return $status;
256 }
257
258 /**
259 * @see FileBackendStore::doMoveInternal()
260 * @return Status
261 */
262 protected function doMoveInternal( array $params ) {
263 $status = Status::newGood();
264
265 $source = $this->resolveToFSPath( $params['src'] );
266 if ( $source === null ) {
267 $status->fatal( 'backend-fail-invalidpath', $params['src'] );
268 return $status;
269 }
270
271 $dest = $this->resolveToFSPath( $params['dst'] );
272 if ( $dest === null ) {
273 $status->fatal( 'backend-fail-invalidpath', $params['dst'] );
274 return $status;
275 }
276
277 if ( file_exists( $dest ) ) {
278 if ( !empty( $params['overwrite'] ) ) {
279 // Windows does not support moving over existing files
280 if ( wfIsWindows() ) {
281 $ok = unlink( $dest );
282 if ( !$ok ) {
283 $status->fatal( 'backend-fail-delete', $params['dst'] );
284 return $status;
285 }
286 }
287 } else {
288 $status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
289 return $status;
290 }
291 }
292
293 $ok = rename( $source, $dest );
294 clearstatcache(); // file no longer at source
295 if ( !$ok ) {
296 $status->fatal( 'backend-fail-move', $params['src'], $params['dst'] );
297 return $status;
298 }
299
300 return $status;
301 }
302
303 /**
304 * @see FileBackendStore::doDeleteInternal()
305 * @return Status
306 */
307 protected function doDeleteInternal( array $params ) {
308 $status = Status::newGood();
309
310 $source = $this->resolveToFSPath( $params['src'] );
311 if ( $source === null ) {
312 $status->fatal( 'backend-fail-invalidpath', $params['src'] );
313 return $status;
314 }
315
316 if ( !is_file( $source ) ) {
317 if ( empty( $params['ignoreMissingSource'] ) ) {
318 $status->fatal( 'backend-fail-delete', $params['src'] );
319 }
320 return $status; // do nothing; either OK or bad status
321 }
322
323 $ok = unlink( $source );
324 if ( !$ok ) {
325 $status->fatal( 'backend-fail-delete', $params['src'] );
326 return $status;
327 }
328
329 return $status;
330 }
331
332 /**
333 * @see FileBackendStore::doCreateInternal()
334 * @return Status
335 */
336 protected function doCreateInternal( array $params ) {
337 $status = Status::newGood();
338
339 $dest = $this->resolveToFSPath( $params['dst'] );
340 if ( $dest === null ) {
341 $status->fatal( 'backend-fail-invalidpath', $params['dst'] );
342 return $status;
343 }
344
345 if ( file_exists( $dest ) ) {
346 if ( !empty( $params['overwrite'] ) ) {
347 $ok = unlink( $dest );
348 if ( !$ok ) {
349 $status->fatal( 'backend-fail-delete', $params['dst'] );
350 return $status;
351 }
352 } else {
353 $status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
354 return $status;
355 }
356 }
357
358 $bytes = file_put_contents( $dest, $params['content'] );
359 if ( $bytes === false ) {
360 $status->fatal( 'backend-fail-create', $params['dst'] );
361 return $status;
362 }
363
364 $this->chmod( $dest );
365
366 return $status;
367 }
368
369 /**
370 * @see FileBackendStore::doPrepareInternal()
371 * @return Status
372 */
373 protected function doPrepareInternal( $fullCont, $dirRel, array $params ) {
374 $status = Status::newGood();
375 list( $b, $shortCont, $r ) = FileBackend::splitStoragePath( $params['dir'] );
376 $contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
377 $dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
378 if ( !wfMkdirParents( $dir ) ) { // make directory and its parents
379 $status->fatal( 'directorycreateerror', $params['dir'] );
380 } elseif ( !is_writable( $dir ) ) {
381 $status->fatal( 'directoryreadonlyerror', $params['dir'] );
382 } elseif ( !is_readable( $dir ) ) {
383 $status->fatal( 'directorynotreadableerror', $params['dir'] );
384 }
385 return $status;
386 }
387
388 /**
389 * @see FileBackendStore::doSecureInternal()
390 * @return Status
391 */
392 protected function doSecureInternal( $fullCont, $dirRel, array $params ) {
393 $status = Status::newGood();
394 list( $b, $shortCont, $r ) = FileBackend::splitStoragePath( $params['dir'] );
395 $contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
396 $dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
397 // Seed new directories with a blank index.html, to prevent crawling...
398 if ( !empty( $params['noListing'] ) && !file_exists( "{$dir}/index.html" ) ) {
399 $bytes = file_put_contents( "{$dir}/index.html", '' );
400 if ( !$bytes ) {
401 $status->fatal( 'backend-fail-create', $params['dir'] . '/index.html' );
402 return $status;
403 }
404 }
405 // Add a .htaccess file to the root of the container...
406 if ( !empty( $params['noAccess'] ) ) {
407 if ( !file_exists( "{$contRoot}/.htaccess" ) ) {
408 $bytes = file_put_contents( "{$contRoot}/.htaccess", "Deny from all\n" );
409 if ( !$bytes ) {
410 $storeDir = "mwstore://{$this->name}/{$shortCont}";
411 $status->fatal( 'backend-fail-create', "{$storeDir}/.htaccess" );
412 return $status;
413 }
414 }
415 }
416 return $status;
417 }
418
419 /**
420 * @see FileBackendStore::doCleanInternal()
421 * @return Status
422 */
423 protected function doCleanInternal( $fullCont, $dirRel, array $params ) {
424 $status = Status::newGood();
425 list( $b, $shortCont, $r ) = FileBackend::splitStoragePath( $params['dir'] );
426 $contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
427 $dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
428 wfSuppressWarnings();
429 if ( is_dir( $dir ) ) {
430 rmdir( $dir ); // remove directory if empty
431 }
432 wfRestoreWarnings();
433 return $status;
434 }
435
436 /**
437 * @see FileBackendStore::doFileExists()
438 * @return array|bool|null
439 */
440 protected function doGetFileStat( array $params ) {
441 $source = $this->resolveToFSPath( $params['src'] );
442 if ( $source === null ) {
443 return false; // invalid storage path
444 }
445
446 $this->trapWarnings(); // don't trust 'false' if there were errors
447 $stat = is_file( $source ) ? stat( $source ) : false; // regular files only
448 $hadError = $this->untrapWarnings();
449
450 if ( $stat ) {
451 return array(
452 'mtime' => wfTimestamp( TS_MW, $stat['mtime'] ),
453 'size' => $stat['size']
454 );
455 } elseif ( !$hadError ) {
456 return false; // file does not exist
457 } else {
458 return null; // failure
459 }
460 }
461
462 /**
463 * @see FileBackendStore::doClearCache()
464 */
465 protected function doClearCache( array $paths = null ) {
466 clearstatcache(); // clear the PHP file stat cache
467 }
468
469 /**
470 * @see FileBackendStore::doDirectoryExists()
471 * @return bool|null
472 */
473 protected function doDirectoryExists( $fullCont, $dirRel, array $params ) {
474 list( $b, $shortCont, $r ) = FileBackend::splitStoragePath( $params['dir'] );
475 $contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
476 $dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
477
478 $this->trapWarnings(); // don't trust 'false' if there were errors
479 $exists = is_dir( $dir );
480 $hadError = $this->untrapWarnings();
481
482 return $hadError ? null : $exists;
483 }
484
485 /**
486 * @see FileBackendStore::getDirectoryListInternal()
487 * @return Array|null
488 */
489 public function getDirectoryListInternal( $fullCont, $dirRel, array $params ) {
490 list( $b, $shortCont, $r ) = FileBackend::splitStoragePath( $params['dir'] );
491 $contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
492 $dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
493 $exists = is_dir( $dir );
494 if ( !$exists ) {
495 wfDebug( __METHOD__ . "() given directory does not exist: '$dir'\n" );
496 return array(); // nothing under this dir
497 } elseif ( !is_readable( $dir ) ) {
498 wfDebug( __METHOD__ . "() given directory is unreadable: '$dir'\n" );
499 return null; // bad permissions?
500 }
501 return new FSFileBackendDirList( $dir, $params );
502 }
503
504 /**
505 * @see FileBackendStore::getFileListInternal()
506 * @return array|FSFileBackendFileList|null
507 */
508 public function getFileListInternal( $fullCont, $dirRel, array $params ) {
509 list( $b, $shortCont, $r ) = FileBackend::splitStoragePath( $params['dir'] );
510 $contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
511 $dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
512 $exists = is_dir( $dir );
513 if ( !$exists ) {
514 wfDebug( __METHOD__ . "() given directory does not exist: '$dir'\n" );
515 return array(); // nothing under this dir
516 } elseif ( !is_readable( $dir ) ) {
517 wfDebug( __METHOD__ . "() given directory is unreadable: '$dir'\n" );
518 return null; // bad permissions?
519 }
520 return new FSFileBackendFileList( $dir, $params );
521 }
522
523 /**
524 * @see FileBackendStore::getLocalReference()
525 * @return FSFile|null
526 */
527 public function getLocalReference( array $params ) {
528 $source = $this->resolveToFSPath( $params['src'] );
529 if ( $source === null ) {
530 return null;
531 }
532 return new FSFile( $source );
533 }
534
535 /**
536 * @see FileBackendStore::getLocalCopy()
537 * @return null|TempFSFile
538 */
539 public function getLocalCopy( array $params ) {
540 $source = $this->resolveToFSPath( $params['src'] );
541 if ( $source === null ) {
542 return null;
543 }
544
545 // Create a new temporary file with the same extension...
546 $ext = FileBackend::extensionFromPath( $params['src'] );
547 $tmpFile = TempFSFile::factory( wfBaseName( $source ) . '_', $ext );
548 if ( !$tmpFile ) {
549 return null;
550 }
551 $tmpPath = $tmpFile->getPath();
552
553 // Copy the source file over the temp file
554 $ok = copy( $source, $tmpPath );
555 if ( !$ok ) {
556 return null;
557 }
558
559 $this->chmod( $tmpPath );
560
561 return $tmpFile;
562 }
563
564 /**
565 * @see FileBackendStore::directoriesAreVirtual()
566 * @return bool
567 */
568 protected function directoriesAreVirtual() {
569 return false;
570 }
571
572 /**
573 * Chmod a file, suppressing the warnings
574 *
575 * @param $path string Absolute file system path
576 * @return bool Success
577 */
578 protected function chmod( $path ) {
579 wfSuppressWarnings();
580 $ok = chmod( $path, $this->fileMode );
581 wfRestoreWarnings();
582
583 return $ok;
584 }
585
586 /**
587 * Listen for E_WARNING errors and track whether any happen
588 *
589 * @return bool
590 */
591 protected function trapWarnings() {
592 $this->hadWarningErrors[] = false; // push to stack
593 set_error_handler( array( $this, 'handleWarning' ), E_WARNING );
594 return false; // invoke normal PHP error handler
595 }
596
597 /**
598 * Stop listening for E_WARNING errors and return true if any happened
599 *
600 * @return bool
601 */
602 protected function untrapWarnings() {
603 restore_error_handler(); // restore previous handler
604 return array_pop( $this->hadWarningErrors ); // pop from stack
605 }
606
607 private function handleWarning() {
608 $this->hadWarningErrors[count( $this->hadWarningErrors ) - 1] = true;
609 return true; // suppress from PHP handler
610 }
611 }
612
613 /**
614 * Wrapper around RecursiveDirectoryIterator/DirectoryIterator that
615 * catches exception or does any custom behavoir that we may want.
616 * Do not use this class from places outside FSFileBackend.
617 *
618 * @ingroup FileBackend
619 */
620 abstract class FSFileBackendList implements Iterator {
621 /** @var Iterator */
622 protected $iter;
623 protected $suffixStart; // integer
624 protected $pos = 0; // integer
625 /** @var Array */
626 protected $params = array();
627
628 /**
629 * @param $dir string file system directory
630 */
631 public function __construct( $dir, array $params ) {
632 $dir = realpath( $dir ); // normalize
633 $this->suffixStart = strlen( $dir ) + 1; // size of "path/to/dir/"
634 $this->params = $params;
635
636 try {
637 $this->iter = $this->initIterator( $dir );
638 } catch ( UnexpectedValueException $e ) {
639 $this->iter = null; // bad permissions? deleted?
640 }
641 }
642
643 /**
644 * Return an appropriate iterator object to wrap
645 *
646 * @param $dir string file system directory
647 * @return Iterator
648 */
649 protected function initIterator( $dir ) {
650 if ( !empty( $this->params['topOnly'] ) ) { // non-recursive
651 # Get an iterator that will get direct sub-nodes
652 return new DirectoryIterator( $dir );
653 } else { // recursive
654 # Get an iterator that will return leaf nodes (non-directories)
655 # RecursiveDirectoryIterator extends FilesystemIterator.
656 # FilesystemIterator::SKIP_DOTS default is inconsistent in PHP 5.3.x.
657 $flags = FilesystemIterator::CURRENT_AS_SELF | FilesystemIterator::SKIP_DOTS;
658 return new RecursiveIteratorIterator(
659 new RecursiveDirectoryIterator( $dir, $flags ),
660 RecursiveIteratorIterator::CHILD_FIRST // include dirs
661 );
662 }
663 }
664
665 /**
666 * @see Iterator::key()
667 * @return integer
668 */
669 public function key() {
670 return $this->pos;
671 }
672
673 /**
674 * @see Iterator::current()
675 * @return string|bool String or false
676 */
677 public function current() {
678 return $this->getRelPath( $this->iter->current()->getPathname() );
679 }
680
681 /**
682 * @see Iterator::next()
683 * @return void
684 */
685 public function next() {
686 try {
687 $this->iter->next();
688 $this->filterViaNext();
689 } catch ( UnexpectedValueException $e ) {
690 $this->iter = null;
691 }
692 ++$this->pos;
693 }
694
695 /**
696 * @see Iterator::rewind()
697 * @return void
698 */
699 public function rewind() {
700 $this->pos = 0;
701 try {
702 $this->iter->rewind();
703 $this->filterViaNext();
704 } catch ( UnexpectedValueException $e ) {
705 $this->iter = null;
706 }
707 }
708
709 /**
710 * @see Iterator::valid()
711 * @return bool
712 */
713 public function valid() {
714 return $this->iter && $this->iter->valid();
715 }
716
717 /**
718 * Filter out items by advancing to the next ones
719 */
720 protected function filterViaNext() {}
721
722 /**
723 * Return only the relative path and normalize slashes to FileBackend-style.
724 * Uses the "real path" since the suffix is based upon that.
725 *
726 * @param $path string
727 * @return string
728 */
729 protected function getRelPath( $path ) {
730 return strtr( substr( realpath( $path ), $this->suffixStart ), '\\', '/' );
731 }
732 }
733
734 class FSFileBackendDirList extends FSFileBackendList {
735 protected function filterViaNext() {
736 while ( $this->iter->valid() ) {
737 if ( $this->iter->current()->isDot() || !$this->iter->current()->isDir() ) {
738 $this->iter->next(); // skip non-directories and dot files
739 } else {
740 break;
741 }
742 }
743 }
744 }
745
746 class FSFileBackendFileList extends FSFileBackendList {
747 protected function filterViaNext() {
748 while ( $this->iter->valid() ) {
749 if ( !$this->iter->current()->isFile() ) {
750 $this->iter->next(); // skip non-files and dot files
751 } else {
752 break;
753 }
754 }
755 }
756 }