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