Merge "Don't check namespace in SpecialWantedtemplates"
[lhc/web/wiklou.git] / includes / filebackend / FileBackendMultiWrite.php
1 <?php
2 /**
3 * Proxy backend that mirrors writes to several internal backends.
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 Proxy backend that mirrors writes to several internal backends.
27 *
28 * This class defines a multi-write backend. Multiple backends can be
29 * registered to this proxy backend and it will act as a single backend.
30 * Use this when all access to those backends is through this proxy backend.
31 * At least one of the backends must be declared the "master" backend.
32 *
33 * Only use this class when transitioning from one storage system to another.
34 *
35 * Read operations are only done on the 'master' backend for consistency.
36 * Write operations are performed on all backends, in the order defined.
37 * If an operation fails on one backend it will be rolled back from the others.
38 *
39 * @ingroup FileBackend
40 * @since 1.19
41 */
42 class FileBackendMultiWrite extends FileBackend {
43 /** @var array Prioritized list of FileBackendStore objects.
44 * array of (backend index => backends)
45 */
46 protected $backends = array();
47
48 /** @var int Index of master backend */
49 protected $masterIndex = -1;
50
51 /** @var int Bitfield */
52 protected $syncChecks = 0;
53
54 /** @var string|bool */
55 protected $autoResync = false;
56
57 /** @var array */
58 protected $noPushDirConts = array();
59
60 /** @var bool */
61 protected $noPushQuickOps = false;
62
63 /* Possible internal backend consistency checks */
64 const CHECK_SIZE = 1;
65 const CHECK_TIME = 2;
66 const CHECK_SHA1 = 4;
67
68 /**
69 * Construct a proxy backend that consists of several internal backends.
70 * Locking, journaling, and read-only checks are handled by the proxy backend.
71 *
72 * Additional $config params include:
73 * - backends : Array of backend config and multi-backend settings.
74 * Each value is the config used in the constructor of a
75 * FileBackendStore class, but with these additional settings:
76 * - class : The name of the backend class
77 * - isMultiMaster : This must be set for one backend.
78 * - template: : If given a backend name, this will use
79 * the config of that backend as a template.
80 * Values specified here take precedence.
81 * - syncChecks : Integer bitfield of internal backend sync checks to perform.
82 * Possible bits include the FileBackendMultiWrite::CHECK_* constants.
83 * There are constants for SIZE, TIME, and SHA1.
84 * The checks are done before allowing any file operations.
85 * - autoResync : Automatically resync the clone backends to the master backend
86 * when pre-operation sync checks fail. This should only be used
87 * if the master backend is stable and not missing any files.
88 * Use "conservative" to limit resyncing to copying newer master
89 * backend files over older (or non-existing) clone backend files.
90 * Cases that cannot be handled will result in operation abortion.
91 * - noPushQuickOps : (hack) Only apply doQuickOperations() to the master backend.
92 * - noPushDirConts : (hack) Only apply directory functions to the master backend.
93 *
94 * @param array $config
95 * @throws FileBackendError
96 */
97 public function __construct( array $config ) {
98 parent::__construct( $config );
99 $this->syncChecks = isset( $config['syncChecks'] )
100 ? $config['syncChecks']
101 : self::CHECK_SIZE;
102 $this->autoResync = isset( $config['autoResync'] )
103 ? $config['autoResync']
104 : false;
105 $this->noPushQuickOps = isset( $config['noPushQuickOps'] )
106 ? $config['noPushQuickOps']
107 : false;
108 $this->noPushDirConts = isset( $config['noPushDirConts'] )
109 ? $config['noPushDirConts']
110 : array();
111 // Construct backends here rather than via registration
112 // to keep these backends hidden from outside the proxy.
113 $namesUsed = array();
114 foreach ( $config['backends'] as $index => $config ) {
115 if ( isset( $config['template'] ) ) {
116 // Config is just a modified version of a registered backend's.
117 // This should only be used when that config is used only by this backend.
118 $config = $config + FileBackendGroup::singleton()->config( $config['template'] );
119 }
120 $name = $config['name'];
121 if ( isset( $namesUsed[$name] ) ) { // don't break FileOp predicates
122 throw new FileBackendError( "Two or more backends defined with the name $name." );
123 }
124 $namesUsed[$name] = 1;
125 // Alter certain sub-backend settings for sanity
126 unset( $config['readOnly'] ); // use proxy backend setting
127 unset( $config['fileJournal'] ); // use proxy backend journal
128 unset( $config['lockManager'] ); // lock under proxy backend
129 $config['wikiId'] = $this->wikiId; // use the proxy backend wiki ID
130 if ( !empty( $config['isMultiMaster'] ) ) {
131 if ( $this->masterIndex >= 0 ) {
132 throw new FileBackendError( 'More than one master backend defined.' );
133 }
134 $this->masterIndex = $index; // this is the "master"
135 $config['fileJournal'] = $this->fileJournal; // log under proxy backend
136 }
137 // Create sub-backend object
138 if ( !isset( $config['class'] ) ) {
139 throw new FileBackendError( 'No class given for a backend config.' );
140 }
141 $class = $config['class'];
142 $this->backends[$index] = new $class( $config );
143 }
144 if ( $this->masterIndex < 0 ) { // need backends and must have a master
145 throw new FileBackendError( 'No master backend defined.' );
146 }
147 }
148
149 final protected function doOperationsInternal( array $ops, array $opts ) {
150 $status = Status::newGood();
151
152 $mbe = $this->backends[$this->masterIndex]; // convenience
153
154 // Try to lock those files for the scope of this function...
155 if ( empty( $opts['nonLocking'] ) ) {
156 // Try to lock those files for the scope of this function...
157 $scopeLock = $this->getScopedLocksForOps( $ops, $status );
158 if ( !$status->isOK() ) {
159 return $status; // abort
160 }
161 }
162 // Clear any cache entries (after locks acquired)
163 $this->clearCache();
164 $opts['preserveCache'] = true; // only locked files are cached
165 // Get the list of paths to read/write...
166 $relevantPaths = $this->fileStoragePathsForOps( $ops );
167 // Check if the paths are valid and accessible on all backends...
168 $status->merge( $this->accessibilityCheck( $relevantPaths ) );
169 if ( !$status->isOK() ) {
170 return $status; // abort
171 }
172 // Do a consistency check to see if the backends are consistent...
173 $syncStatus = $this->consistencyCheck( $relevantPaths );
174 if ( !$syncStatus->isOK() ) {
175 wfDebugLog( 'FileOperation', get_class( $this ) .
176 " failed sync check: " . FormatJson::encode( $relevantPaths ) );
177 // Try to resync the clone backends to the master on the spot...
178 if ( !$this->autoResync || !$this->resyncFiles( $relevantPaths )->isOK() ) {
179 $status->merge( $syncStatus );
180
181 return $status; // abort
182 }
183 }
184 // Actually attempt the operation batch on the master backend...
185 $realOps = $this->substOpBatchPaths( $ops, $mbe );
186 $masterStatus = $mbe->doOperations( $realOps, $opts );
187 $status->merge( $masterStatus );
188 // Propagate the operations to the clone backends if there were no unexpected errors
189 // and if there were either no expected errors or if the 'force' option was used.
190 // However, if nothing succeeded at all, then don't replicate any of the operations.
191 // If $ops only had one operation, this might avoid backend sync inconsistencies.
192 if ( $masterStatus->isOK() && $masterStatus->successCount > 0 ) {
193 foreach ( $this->backends as $index => $backend ) {
194 if ( $index !== $this->masterIndex ) { // not done already
195 $realOps = $this->substOpBatchPaths( $ops, $backend );
196 $status->merge( $backend->doOperations( $realOps, $opts ) );
197 }
198 }
199 }
200 // Make 'success', 'successCount', and 'failCount' fields reflect
201 // the overall operation, rather than all the batches for each backend.
202 // Do this by only using success values from the master backend's batch.
203 $status->success = $masterStatus->success;
204 $status->successCount = $masterStatus->successCount;
205 $status->failCount = $masterStatus->failCount;
206
207 return $status;
208 }
209
210 /**
211 * Check that a set of files are consistent across all internal backends
212 *
213 * @param array $paths List of storage paths
214 * @return Status
215 */
216 public function consistencyCheck( array $paths ) {
217 $status = Status::newGood();
218 if ( $this->syncChecks == 0 || count( $this->backends ) <= 1 ) {
219 return $status; // skip checks
220 }
221
222 $mBackend = $this->backends[$this->masterIndex];
223 foreach ( $paths as $path ) {
224 $params = array( 'src' => $path, 'latest' => true );
225 $mParams = $this->substOpPaths( $params, $mBackend );
226 // Stat the file on the 'master' backend
227 $mStat = $mBackend->getFileStat( $mParams );
228 if ( $this->syncChecks & self::CHECK_SHA1 ) {
229 $mSha1 = $mBackend->getFileSha1Base36( $mParams );
230 } else {
231 $mSha1 = false;
232 }
233 // Check if all clone backends agree with the master...
234 foreach ( $this->backends as $index => $cBackend ) {
235 if ( $index === $this->masterIndex ) {
236 continue; // master
237 }
238 $cParams = $this->substOpPaths( $params, $cBackend );
239 $cStat = $cBackend->getFileStat( $cParams );
240 if ( $mStat ) { // file is in master
241 if ( !$cStat ) { // file should exist
242 $status->fatal( 'backend-fail-synced', $path );
243 continue;
244 }
245 if ( $this->syncChecks & self::CHECK_SIZE ) {
246 if ( $cStat['size'] != $mStat['size'] ) { // wrong size
247 $status->fatal( 'backend-fail-synced', $path );
248 continue;
249 }
250 }
251 if ( $this->syncChecks & self::CHECK_TIME ) {
252 $mTs = wfTimestamp( TS_UNIX, $mStat['mtime'] );
253 $cTs = wfTimestamp( TS_UNIX, $cStat['mtime'] );
254 if ( abs( $mTs - $cTs ) > 30 ) { // outdated file somewhere
255 $status->fatal( 'backend-fail-synced', $path );
256 continue;
257 }
258 }
259 if ( $this->syncChecks & self::CHECK_SHA1 ) {
260 if ( $cBackend->getFileSha1Base36( $cParams ) !== $mSha1 ) { // wrong SHA1
261 $status->fatal( 'backend-fail-synced', $path );
262 continue;
263 }
264 }
265 } else { // file is not in master
266 if ( $cStat ) { // file should not exist
267 $status->fatal( 'backend-fail-synced', $path );
268 }
269 }
270 }
271 }
272
273 return $status;
274 }
275
276 /**
277 * Check that a set of file paths are usable across all internal backends
278 *
279 * @param array $paths List of storage paths
280 * @return Status
281 */
282 public function accessibilityCheck( array $paths ) {
283 $status = Status::newGood();
284 if ( count( $this->backends ) <= 1 ) {
285 return $status; // skip checks
286 }
287
288 foreach ( $paths as $path ) {
289 foreach ( $this->backends as $backend ) {
290 $realPath = $this->substPaths( $path, $backend );
291 if ( !$backend->isPathUsableInternal( $realPath ) ) {
292 $status->fatal( 'backend-fail-usable', $path );
293 }
294 }
295 }
296
297 return $status;
298 }
299
300 /**
301 * Check that a set of files are consistent across all internal backends
302 * and re-synchronize those files against the "multi master" if needed.
303 *
304 * @param array $paths List of storage paths
305 * @return Status
306 */
307 public function resyncFiles( array $paths ) {
308 $status = Status::newGood();
309
310 $mBackend = $this->backends[$this->masterIndex];
311 foreach ( $paths as $path ) {
312 $mPath = $this->substPaths( $path, $mBackend );
313 $mSha1 = $mBackend->getFileSha1Base36( array( 'src' => $mPath, 'latest' => true ) );
314 $mStat = $mBackend->getFileStat( array( 'src' => $mPath, 'latest' => true ) );
315 if ( $mStat === null || ( $mSha1 !== false && !$mStat ) ) { // sanity
316 $status->fatal( 'backend-fail-internal', $this->name );
317 wfDebugLog( 'FileOperation', __METHOD__
318 . ': File is not available on the master backend' );
319 continue; // file is not available on the master backend...
320 }
321 // Check of all clone backends agree with the master...
322 foreach ( $this->backends as $index => $cBackend ) {
323 if ( $index === $this->masterIndex ) {
324 continue; // master
325 }
326 $cPath = $this->substPaths( $path, $cBackend );
327 $cSha1 = $cBackend->getFileSha1Base36( array( 'src' => $cPath, 'latest' => true ) );
328 $cStat = $cBackend->getFileStat( array( 'src' => $cPath, 'latest' => true ) );
329 if ( $cStat === null || ( $cSha1 !== false && !$cStat ) ) { // sanity
330 $status->fatal( 'backend-fail-internal', $cBackend->getName() );
331 wfDebugLog( 'FileOperation', __METHOD__ .
332 ': File is not available on the clone backend' );
333 continue; // file is not available on the clone backend...
334 }
335 if ( $mSha1 === $cSha1 ) {
336 // already synced; nothing to do
337 } elseif ( $mSha1 !== false ) { // file is in master
338 if ( $this->autoResync === 'conservative'
339 && $cStat && $cStat['mtime'] > $mStat['mtime']
340 ) {
341 $status->fatal( 'backend-fail-synced', $path );
342 continue; // don't rollback data
343 }
344 $fsFile = $mBackend->getLocalReference(
345 array( 'src' => $mPath, 'latest' => true ) );
346 $status->merge( $cBackend->quickStore(
347 array( 'src' => $fsFile->getPath(), 'dst' => $cPath )
348 ) );
349 } elseif ( $mStat === false ) { // file is not in master
350 if ( $this->autoResync === 'conservative' ) {
351 $status->fatal( 'backend-fail-synced', $path );
352 continue; // don't delete data
353 }
354 $status->merge( $cBackend->quickDelete( array( 'src' => $cPath ) ) );
355 }
356 }
357 }
358
359 return $status;
360 }
361
362 /**
363 * Get a list of file storage paths to read or write for a list of operations
364 *
365 * @param array $ops Same format as doOperations()
366 * @return array List of storage paths to files (does not include directories)
367 */
368 protected function fileStoragePathsForOps( array $ops ) {
369 $paths = array();
370 foreach ( $ops as $op ) {
371 if ( isset( $op['src'] ) ) {
372 // For things like copy/move/delete with "ignoreMissingSource" and there
373 // is no source file, nothing should happen and there should be no errors.
374 if ( empty( $op['ignoreMissingSource'] )
375 || $this->fileExists( array( 'src' => $op['src'] ) )
376 ) {
377 $paths[] = $op['src'];
378 }
379 }
380 if ( isset( $op['srcs'] ) ) {
381 $paths = array_merge( $paths, $op['srcs'] );
382 }
383 if ( isset( $op['dst'] ) ) {
384 $paths[] = $op['dst'];
385 }
386 }
387
388 return array_values( array_unique( array_filter( $paths, 'FileBackend::isStoragePath' ) ) );
389 }
390
391 /**
392 * Substitute the backend name in storage path parameters
393 * for a set of operations with that of a given internal backend.
394 *
395 * @param array $ops List of file operation arrays
396 * @param FileBackendStore $backend
397 * @return array
398 */
399 protected function substOpBatchPaths( array $ops, FileBackendStore $backend ) {
400 $newOps = array(); // operations
401 foreach ( $ops as $op ) {
402 $newOp = $op; // operation
403 foreach ( array( 'src', 'srcs', 'dst', 'dir' ) as $par ) {
404 if ( isset( $newOp[$par] ) ) { // string or array
405 $newOp[$par] = $this->substPaths( $newOp[$par], $backend );
406 }
407 }
408 $newOps[] = $newOp;
409 }
410
411 return $newOps;
412 }
413
414 /**
415 * Same as substOpBatchPaths() but for a single operation
416 *
417 * @param array $ops File operation array
418 * @param FileBackendStore $backend
419 * @return array
420 */
421 protected function substOpPaths( array $ops, FileBackendStore $backend ) {
422 $newOps = $this->substOpBatchPaths( array( $ops ), $backend );
423
424 return $newOps[0];
425 }
426
427 /**
428 * Substitute the backend of storage paths with an internal backend's name
429 *
430 * @param array|string $paths List of paths or single string path
431 * @param FileBackendStore $backend
432 * @return array|string
433 */
434 protected function substPaths( $paths, FileBackendStore $backend ) {
435 return preg_replace(
436 '!^mwstore://' . preg_quote( $this->name, '!' ) . '/!',
437 StringUtils::escapeRegexReplacement( "mwstore://{$backend->getName()}/" ),
438 $paths // string or array
439 );
440 }
441
442 /**
443 * Substitute the backend of internal storage paths with the proxy backend's name
444 *
445 * @param array|string $paths List of paths or single string path
446 * @return array|string
447 */
448 protected function unsubstPaths( $paths ) {
449 return preg_replace(
450 '!^mwstore://([^/]+)!',
451 StringUtils::escapeRegexReplacement( "mwstore://{$this->name}" ),
452 $paths // string or array
453 );
454 }
455
456 protected function doQuickOperationsInternal( array $ops ) {
457 $status = Status::newGood();
458 // Do the operations on the master backend; setting Status fields...
459 $realOps = $this->substOpBatchPaths( $ops, $this->backends[$this->masterIndex] );
460 $masterStatus = $this->backends[$this->masterIndex]->doQuickOperations( $realOps );
461 $status->merge( $masterStatus );
462 // Propagate the operations to the clone backends...
463 if ( !$this->noPushQuickOps ) {
464 foreach ( $this->backends as $index => $backend ) {
465 if ( $index !== $this->masterIndex ) { // not done already
466 $realOps = $this->substOpBatchPaths( $ops, $backend );
467 $status->merge( $backend->doQuickOperations( $realOps ) );
468 }
469 }
470 }
471 // Make 'success', 'successCount', and 'failCount' fields reflect
472 // the overall operation, rather than all the batches for each backend.
473 // Do this by only using success values from the master backend's batch.
474 $status->success = $masterStatus->success;
475 $status->successCount = $masterStatus->successCount;
476 $status->failCount = $masterStatus->failCount;
477
478 return $status;
479 }
480
481 /**
482 * @param string $path Storage path
483 * @return bool Path container should have dir changes pushed to all backends
484 */
485 protected function replicateContainerDirChanges( $path ) {
486 list( , $shortCont, ) = self::splitStoragePath( $path );
487
488 return !in_array( $shortCont, $this->noPushDirConts );
489 }
490
491 protected function doPrepare( array $params ) {
492 $status = Status::newGood();
493 $replicate = $this->replicateContainerDirChanges( $params['dir'] );
494 foreach ( $this->backends as $index => $backend ) {
495 if ( $replicate || $index == $this->masterIndex ) {
496 $realParams = $this->substOpPaths( $params, $backend );
497 $status->merge( $backend->doPrepare( $realParams ) );
498 }
499 }
500
501 return $status;
502 }
503
504 protected function doSecure( array $params ) {
505 $status = Status::newGood();
506 $replicate = $this->replicateContainerDirChanges( $params['dir'] );
507 foreach ( $this->backends as $index => $backend ) {
508 if ( $replicate || $index == $this->masterIndex ) {
509 $realParams = $this->substOpPaths( $params, $backend );
510 $status->merge( $backend->doSecure( $realParams ) );
511 }
512 }
513
514 return $status;
515 }
516
517 protected function doPublish( array $params ) {
518 $status = Status::newGood();
519 $replicate = $this->replicateContainerDirChanges( $params['dir'] );
520 foreach ( $this->backends as $index => $backend ) {
521 if ( $replicate || $index == $this->masterIndex ) {
522 $realParams = $this->substOpPaths( $params, $backend );
523 $status->merge( $backend->doPublish( $realParams ) );
524 }
525 }
526
527 return $status;
528 }
529
530 protected function doClean( array $params ) {
531 $status = Status::newGood();
532 $replicate = $this->replicateContainerDirChanges( $params['dir'] );
533 foreach ( $this->backends as $index => $backend ) {
534 if ( $replicate || $index == $this->masterIndex ) {
535 $realParams = $this->substOpPaths( $params, $backend );
536 $status->merge( $backend->doClean( $realParams ) );
537 }
538 }
539
540 return $status;
541 }
542
543 public function concatenate( array $params ) {
544 // We are writing to an FS file, so we don't need to do this per-backend
545 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
546
547 return $this->backends[$this->masterIndex]->concatenate( $realParams );
548 }
549
550 public function fileExists( array $params ) {
551 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
552
553 return $this->backends[$this->masterIndex]->fileExists( $realParams );
554 }
555
556 public function getFileTimestamp( array $params ) {
557 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
558
559 return $this->backends[$this->masterIndex]->getFileTimestamp( $realParams );
560 }
561
562 public function getFileSize( array $params ) {
563 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
564
565 return $this->backends[$this->masterIndex]->getFileSize( $realParams );
566 }
567
568 public function getFileStat( array $params ) {
569 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
570
571 return $this->backends[$this->masterIndex]->getFileStat( $realParams );
572 }
573
574 public function getFileXAttributes( array $params ) {
575 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
576
577 return $this->backends[$this->masterIndex]->getFileXAttributes( $realParams );
578 }
579
580 public function getFileContentsMulti( array $params ) {
581 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
582 $contentsM = $this->backends[$this->masterIndex]->getFileContentsMulti( $realParams );
583
584 $contents = array(); // (path => FSFile) mapping using the proxy backend's name
585 foreach ( $contentsM as $path => $data ) {
586 $contents[$this->unsubstPaths( $path )] = $data;
587 }
588
589 return $contents;
590 }
591
592 public function getFileSha1Base36( array $params ) {
593 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
594
595 return $this->backends[$this->masterIndex]->getFileSha1Base36( $realParams );
596 }
597
598 public function getFileProps( array $params ) {
599 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
600
601 return $this->backends[$this->masterIndex]->getFileProps( $realParams );
602 }
603
604 public function streamFile( array $params ) {
605 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
606
607 return $this->backends[$this->masterIndex]->streamFile( $realParams );
608 }
609
610 public function getLocalReferenceMulti( array $params ) {
611 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
612 $fsFilesM = $this->backends[$this->masterIndex]->getLocalReferenceMulti( $realParams );
613
614 $fsFiles = array(); // (path => FSFile) mapping using the proxy backend's name
615 foreach ( $fsFilesM as $path => $fsFile ) {
616 $fsFiles[$this->unsubstPaths( $path )] = $fsFile;
617 }
618
619 return $fsFiles;
620 }
621
622 public function getLocalCopyMulti( array $params ) {
623 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
624 $tempFilesM = $this->backends[$this->masterIndex]->getLocalCopyMulti( $realParams );
625
626 $tempFiles = array(); // (path => TempFSFile) mapping using the proxy backend's name
627 foreach ( $tempFilesM as $path => $tempFile ) {
628 $tempFiles[$this->unsubstPaths( $path )] = $tempFile;
629 }
630
631 return $tempFiles;
632 }
633
634 public function getFileHttpUrl( array $params ) {
635 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
636
637 return $this->backends[$this->masterIndex]->getFileHttpUrl( $realParams );
638 }
639
640 public function directoryExists( array $params ) {
641 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
642
643 return $this->backends[$this->masterIndex]->directoryExists( $realParams );
644 }
645
646 public function getDirectoryList( array $params ) {
647 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
648
649 return $this->backends[$this->masterIndex]->getDirectoryList( $realParams );
650 }
651
652 public function getFileList( array $params ) {
653 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
654
655 return $this->backends[$this->masterIndex]->getFileList( $realParams );
656 }
657
658 public function getFeatures() {
659 return $this->backends[$this->masterIndex]->getFeatures();
660 }
661
662 public function clearCache( array $paths = null ) {
663 foreach ( $this->backends as $backend ) {
664 $realPaths = is_array( $paths ) ? $this->substPaths( $paths, $backend ) : null;
665 $backend->clearCache( $realPaths );
666 }
667 }
668
669 public function preloadCache( array $paths ) {
670 $realPaths = $this->substPaths( $paths, $this->backends[$this->masterIndex] );
671 $this->backends[$this->masterIndex]->preloadCache( $realPaths );
672 }
673
674 public function preloadFileStat( array $params ) {
675 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
676 return $this->backends[$this->masterIndex]->preloadFileStat( $realParams );
677 }
678
679 public function getScopedLocksForOps( array $ops, Status $status ) {
680 $realOps = $this->substOpBatchPaths( $ops, $this->backends[$this->masterIndex] );
681 $fileOps = $this->backends[$this->masterIndex]->getOperationsInternal( $realOps );
682 // Get the paths to lock from the master backend
683 $paths = $this->backends[$this->masterIndex]->getPathsToLockForOpsInternal( $fileOps );
684 // Get the paths under the proxy backend's name
685 $pbPaths = array(
686 LockManager::LOCK_UW => $this->unsubstPaths( $paths[LockManager::LOCK_UW] ),
687 LockManager::LOCK_EX => $this->unsubstPaths( $paths[LockManager::LOCK_EX] )
688 );
689
690 // Actually acquire the locks
691 return array( $this->getScopedFileLocks( $pbPaths, 'mixed', $status ) );
692 }
693 }