Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| FileBackendStoreShardListIterator | |
0.00% |
0 / 19 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| accept | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| rewind | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| listFromShard | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | * @ingroup FileBackend |
| 6 | */ |
| 7 | |
| 8 | namespace Wikimedia\FileBackend\FileIteration; |
| 9 | |
| 10 | use AppendIterator; |
| 11 | use FilterIterator; |
| 12 | use Iterator; |
| 13 | use Wikimedia\FileBackend\FileBackendStore; |
| 14 | |
| 15 | /** |
| 16 | * FileBackendStore helper function to handle listings that span container shards. |
| 17 | * Do not use this class from places outside of FileBackendStore. |
| 18 | * |
| 19 | * @ingroup FileBackend |
| 20 | */ |
| 21 | abstract class FileBackendStoreShardListIterator extends FilterIterator { |
| 22 | /** @var FileBackendStore */ |
| 23 | protected $backend; |
| 24 | |
| 25 | /** @var array */ |
| 26 | protected $params; |
| 27 | |
| 28 | /** @var string Full container name */ |
| 29 | protected $container; |
| 30 | |
| 31 | /** @var string Resolved relative path */ |
| 32 | protected $directory; |
| 33 | |
| 34 | /** @var array */ |
| 35 | protected $multiShardPaths = []; // (rel path => 1) |
| 36 | |
| 37 | /** |
| 38 | * @param FileBackendStore $backend |
| 39 | * @param string $container Full storage container name |
| 40 | * @param string $dir Storage directory relative to container |
| 41 | * @param array $suffixes List of container shard suffixes |
| 42 | * @param array $params |
| 43 | */ |
| 44 | public function __construct( |
| 45 | FileBackendStore $backend, $container, $dir, array $suffixes, array $params |
| 46 | ) { |
| 47 | $this->backend = $backend; |
| 48 | $this->container = $container; |
| 49 | $this->directory = $dir; |
| 50 | $this->params = $params; |
| 51 | |
| 52 | $iter = new AppendIterator(); |
| 53 | foreach ( $suffixes as $suffix ) { |
| 54 | $iter->append( $this->listFromShard( $this->container . $suffix ) ); |
| 55 | } |
| 56 | |
| 57 | parent::__construct( $iter ); |
| 58 | } |
| 59 | |
| 60 | public function accept(): bool { |
| 61 | $inner = $this->getInnerIterator(); |
| 62 | '@phan-var AppendIterator $inner'; |
| 63 | $rel = $inner->current(); // path relative to given directory |
| 64 | $path = $this->params['dir'] . "/{$rel}"; // full storage path |
| 65 | if ( $this->backend->isSingleShardPathInternal( $path ) ) { |
| 66 | return true; // path is only on one shard; no issue with duplicates |
| 67 | } elseif ( isset( $this->multiShardPaths[$rel] ) ) { |
| 68 | // Don't keep listing paths that are on multiple shards |
| 69 | return false; |
| 70 | } else { |
| 71 | $this->multiShardPaths[$rel] = 1; |
| 72 | |
| 73 | return true; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | public function rewind(): void { |
| 78 | parent::rewind(); |
| 79 | $this->multiShardPaths = []; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Get the list for a given container shard |
| 84 | * |
| 85 | * @param string $container Resolved container name |
| 86 | * @return Iterator |
| 87 | */ |
| 88 | abstract protected function listFromShard( $container ); |
| 89 | } |
| 90 | |
| 91 | /** @deprecated class alias since 1.43 */ |
| 92 | class_alias( FileBackendStoreShardListIterator::class, 'FileBackendStoreShardListIterator' ); |