Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
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 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | * @ingroup FileBackend |
20 | */ |
21 | |
22 | /** |
23 | * FileBackendStore helper function to handle listings that span container shards. |
24 | * Do not use this class from places outside of FileBackendStore. |
25 | * |
26 | * @ingroup FileBackend |
27 | */ |
28 | abstract class FileBackendStoreShardListIterator extends FilterIterator { |
29 | /** @var FileBackendStore */ |
30 | protected $backend; |
31 | |
32 | /** @var array */ |
33 | protected $params; |
34 | |
35 | /** @var string Full container name */ |
36 | protected $container; |
37 | |
38 | /** @var string Resolved relative path */ |
39 | protected $directory; |
40 | |
41 | /** @var array */ |
42 | protected $multiShardPaths = []; // (rel path => 1) |
43 | |
44 | /** |
45 | * @param FileBackendStore $backend |
46 | * @param string $container Full storage container name |
47 | * @param string $dir Storage directory relative to container |
48 | * @param array $suffixes List of container shard suffixes |
49 | * @param array $params |
50 | */ |
51 | public function __construct( |
52 | FileBackendStore $backend, $container, $dir, array $suffixes, array $params |
53 | ) { |
54 | $this->backend = $backend; |
55 | $this->container = $container; |
56 | $this->directory = $dir; |
57 | $this->params = $params; |
58 | |
59 | $iter = new AppendIterator(); |
60 | foreach ( $suffixes as $suffix ) { |
61 | $iter->append( $this->listFromShard( $this->container . $suffix ) ); |
62 | } |
63 | |
64 | parent::__construct( $iter ); |
65 | } |
66 | |
67 | public function accept(): bool { |
68 | $inner = $this->getInnerIterator(); |
69 | '@phan-var AppendIterator $inner'; |
70 | $rel = $inner->current(); // path relative to given directory |
71 | $path = $this->params['dir'] . "/{$rel}"; // full storage path |
72 | if ( $this->backend->isSingleShardPathInternal( $path ) ) { |
73 | return true; // path is only on one shard; no issue with duplicates |
74 | } elseif ( isset( $this->multiShardPaths[$rel] ) ) { |
75 | // Don't keep listing paths that are on multiple shards |
76 | return false; |
77 | } else { |
78 | $this->multiShardPaths[$rel] = 1; |
79 | |
80 | return true; |
81 | } |
82 | } |
83 | |
84 | public function rewind(): void { |
85 | parent::rewind(); |
86 | $this->multiShardPaths = []; |
87 | } |
88 | |
89 | /** |
90 | * Get the list for a given container shard |
91 | * |
92 | * @param string $container Resolved container name |
93 | * @return Iterator |
94 | */ |
95 | abstract protected function listFromShard( $container ); |
96 | } |