aboutsummaryrefslogtreecommitdiffstats
path: root/includes
diff options
context:
space:
mode:
authorSiebrand Mazeland <s.mazeland@xs4all.nl>2013-11-22 22:17:15 +0100
committerSiebrand Mazeland <s.mazeland@xs4all.nl>2013-11-22 22:17:15 +0100
commita5c35215e27594ed1577f1748504fee2aafadc4c (patch)
treeefbc991f1ddfe8792d60768bb0319aa0455ce703 /includes
parent8e32a04a1aa4319ff29ed8609202b7f3b7eeee00 (diff)
downloadmediawikicore-a5c35215e27594ed1577f1748504fee2aafadc4c.tar.gz
mediawikicore-a5c35215e27594ed1577f1748504fee2aafadc4c.zip
Update formatting of file backend classes
Change-Id: Ie69c324e2f1ea0b8a654adee06ebda494cebd10c
Diffstat (limited to 'includes')
-rw-r--r--includes/filebackend/FSFile.php13
-rw-r--r--includes/filebackend/FSFileBackend.php36
-rw-r--r--includes/filebackend/FileBackend.php20
-rw-r--r--includes/filebackend/FileBackendGroup.php7
-rw-r--r--includes/filebackend/FileBackendMultiWrite.php34
-rw-r--r--includes/filebackend/FileBackendStore.php49
-rw-r--r--includes/filebackend/FileOp.php47
-rw-r--r--includes/filebackend/FileOpBatch.php5
-rw-r--r--includes/filebackend/SwiftFileBackend.php55
-rw-r--r--includes/filebackend/TempFSFile.php6
-rw-r--r--includes/filebackend/filejournal/DBFileJournal.php4
-rw-r--r--includes/filebackend/filejournal/FileJournal.php5
-rw-r--r--includes/filebackend/lockmanager/DBLockManager.php9
-rw-r--r--includes/filebackend/lockmanager/FSLockManager.php3
-rw-r--r--includes/filebackend/lockmanager/LSLockManager.php2
-rw-r--r--includes/filebackend/lockmanager/LockManager.php5
-rw-r--r--includes/filebackend/lockmanager/LockManagerGroup.php3
-rw-r--r--includes/filebackend/lockmanager/MemcLockManager.php4
-rw-r--r--includes/filebackend/lockmanager/QuorumLockManager.php1
-rw-r--r--includes/filebackend/lockmanager/RedisLockManager.php2
-rw-r--r--includes/filebackend/lockmanager/ScopedLock.php1
21 files changed, 282 insertions, 29 deletions
diff --git a/includes/filebackend/FSFile.php b/includes/filebackend/FSFile.php
index 8f0a13347e43..97ce593114c0 100644
--- a/includes/filebackend/FSFile.php
+++ b/includes/filebackend/FSFile.php
@@ -82,6 +82,7 @@ class FSFile {
if ( $timestamp !== false ) {
$timestamp = wfTimestamp( TS_MW, $timestamp );
}
+
return $timestamp;
}
@@ -98,7 +99,7 @@ class FSFile {
* Get an associative array containing information about
* a file with the given storage path.
*
- * @param Mixed $ext: the file extension, or true to extract it from the filename.
+ * @param mixed $ext The file extension, or true to extract it from the filename.
* Set it to false to ignore the extension.
*
* @return array
@@ -147,6 +148,7 @@ class FSFile {
}
wfProfileOut( __METHOD__ );
+
return $info;
}
@@ -165,6 +167,7 @@ class FSFile {
$info['width'] = 0;
$info['height'] = 0;
$info['bits'] = 0;
+
return $info;
}
@@ -184,6 +187,7 @@ class FSFile {
} else {
$info['bits'] = 0;
}
+
return $info;
}
@@ -202,6 +206,7 @@ class FSFile {
if ( $this->sha1Base36 !== null && !$recache ) {
wfProfileOut( __METHOD__ );
+
return $this->sha1Base36;
}
@@ -214,6 +219,7 @@ class FSFile {
}
wfProfileOut( __METHOD__ );
+
return $this->sha1Base36;
}
@@ -225,6 +231,7 @@ class FSFile {
*/
public static function extensionFromPath( $path ) {
$i = strrpos( $path, '.' );
+
return strtolower( $i ? substr( $path, $i + 1 ) : '' );
}
@@ -232,12 +239,13 @@ class FSFile {
* Get an associative array containing information about a file in the local filesystem.
*
* @param string $path absolute local filesystem path
- * @param Mixed $ext: the file extension, or true to extract it from the filename.
+ * @param mixed $ext The file extension, or true to extract it from the filename.
* Set it to false to ignore the extension.
* @return array
*/
public static function getPropsFromPath( $path, $ext = true ) {
$fsFile = new self( $path );
+
return $fsFile->getProps( $ext );
}
@@ -253,6 +261,7 @@ class FSFile {
*/
public static function getSha1Base36FromPath( $path ) {
$fsFile = new self( $path );
+
return $fsFile->getSha1Base36();
}
}
diff --git a/includes/filebackend/FSFileBackend.php b/includes/filebackend/FSFileBackend.php
index 6d6421627ebf..cacae9b3a767 100644
--- a/includes/filebackend/FSFileBackend.php
+++ b/includes/filebackend/FSFileBackend.php
@@ -90,6 +90,7 @@ class FSFileBackend extends FileBackendStore {
return $relStoragePath;
}
}
+
return null;
}
@@ -125,6 +126,7 @@ class FSFileBackend extends FileBackendStore {
} elseif ( isset( $this->basePath ) ) {
return "{$this->basePath}/{$fullCont}";
}
+
return null; // no container base path defined
}
@@ -144,6 +146,7 @@ class FSFileBackend extends FileBackendStore {
if ( $relPath != '' ) {
$fsPath .= "/{$relPath}";
}
+
return $fsPath;
}
@@ -174,6 +177,7 @@ class FSFileBackend extends FileBackendStore {
$dest = $this->resolveToFSPath( $params['dst'] );
if ( $dest === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['dst'] );
+
return $status;
}
@@ -181,6 +185,7 @@ class FSFileBackend extends FileBackendStore {
$tempFile = TempFSFile::factory( 'create_', 'tmp' );
if ( !$tempFile ) {
$status->fatal( 'backend-fail-create', $params['dst'] );
+
return $status;
}
$this->trapWarnings();
@@ -188,6 +193,7 @@ class FSFileBackend extends FileBackendStore {
$this->untrapWarnings();
if ( $bytes === false ) {
$status->fatal( 'backend-fail-create', $params['dst'] );
+
return $status;
}
$cmd = implode( ' ', array(
@@ -203,6 +209,7 @@ class FSFileBackend extends FileBackendStore {
$this->untrapWarnings();
if ( $bytes === false ) {
$status->fatal( 'backend-fail-create', $params['dst'] );
+
return $status;
}
$this->chmod( $dest );
@@ -227,6 +234,7 @@ class FSFileBackend extends FileBackendStore {
$dest = $this->resolveToFSPath( $params['dst'] );
if ( $dest === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['dst'] );
+
return $status;
}
@@ -248,6 +256,7 @@ class FSFileBackend extends FileBackendStore {
trigger_error( __METHOD__ . ": copy() failed but returned true." );
}
$status->fatal( 'backend-fail-store', $params['src'], $params['dst'] );
+
return $status;
}
$this->chmod( $dest );
@@ -272,12 +281,14 @@ class FSFileBackend extends FileBackendStore {
$source = $this->resolveToFSPath( $params['src'] );
if ( $source === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['src'] );
+
return $status;
}
$dest = $this->resolveToFSPath( $params['dst'] );
if ( $dest === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['dst'] );
+
return $status;
}
@@ -285,6 +296,7 @@ class FSFileBackend extends FileBackendStore {
if ( empty( $params['ignoreMissingSource'] ) ) {
$status->fatal( 'backend-fail-copy', $params['src'] );
}
+
return $status; // do nothing; either OK or bad status
}
@@ -308,6 +320,7 @@ class FSFileBackend extends FileBackendStore {
trigger_error( __METHOD__ . ": copy() failed but returned true." );
}
$status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
+
return $status;
}
$this->chmod( $dest );
@@ -332,12 +345,14 @@ class FSFileBackend extends FileBackendStore {
$source = $this->resolveToFSPath( $params['src'] );
if ( $source === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['src'] );
+
return $status;
}
$dest = $this->resolveToFSPath( $params['dst'] );
if ( $dest === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['dst'] );
+
return $status;
}
@@ -345,6 +360,7 @@ class FSFileBackend extends FileBackendStore {
if ( empty( $params['ignoreMissingSource'] ) ) {
$status->fatal( 'backend-fail-move', $params['src'] );
}
+
return $status; // do nothing; either OK or bad status
}
@@ -362,6 +378,7 @@ class FSFileBackend extends FileBackendStore {
clearstatcache(); // file no longer at source
if ( !$ok ) {
$status->fatal( 'backend-fail-move', $params['src'], $params['dst'] );
+
return $status;
}
}
@@ -385,6 +402,7 @@ class FSFileBackend extends FileBackendStore {
$source = $this->resolveToFSPath( $params['src'] );
if ( $source === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['src'] );
+
return $status;
}
@@ -392,6 +410,7 @@ class FSFileBackend extends FileBackendStore {
if ( empty( $params['ignoreMissingSource'] ) ) {
$status->fatal( 'backend-fail-delete', $params['src'] );
}
+
return $status; // do nothing; either OK or bad status
}
@@ -407,6 +426,7 @@ class FSFileBackend extends FileBackendStore {
$this->untrapWarnings();
if ( !$ok ) {
$status->fatal( 'backend-fail-delete', $params['src'] );
+
return $status;
}
}
@@ -444,6 +464,7 @@ class FSFileBackend extends FileBackendStore {
if ( is_dir( $dir ) && !$existed ) {
$status->merge( $this->doSecureInternal( $fullCont, $dirRel, $params ) );
}
+
return $status;
}
@@ -471,6 +492,7 @@ class FSFileBackend extends FileBackendStore {
$status->fatal( 'backend-fail-create', "{$storeDir}/.htaccess" );
}
}
+
return $status;
}
@@ -498,6 +520,7 @@ class FSFileBackend extends FileBackendStore {
}
$this->untrapWarnings();
}
+
return $status;
}
@@ -511,6 +534,7 @@ class FSFileBackend extends FileBackendStore {
rmdir( $dir ); // remove directory if empty
}
$this->untrapWarnings();
+
return $status;
}
@@ -566,11 +590,14 @@ class FSFileBackend extends FileBackendStore {
$exists = is_dir( $dir );
if ( !$exists ) {
wfDebug( __METHOD__ . "() given directory does not exist: '$dir'\n" );
+
return array(); // nothing under this dir
} elseif ( !is_readable( $dir ) ) {
wfDebug( __METHOD__ . "() given directory is unreadable: '$dir'\n" );
+
return null; // bad permissions?
}
+
return new FSFileBackendDirList( $dir, $params );
}
@@ -585,11 +612,14 @@ class FSFileBackend extends FileBackendStore {
$exists = is_dir( $dir );
if ( !$exists ) {
wfDebug( __METHOD__ . "() given directory does not exist: '$dir'\n" );
+
return array(); // nothing under this dir
} elseif ( !is_readable( $dir ) ) {
wfDebug( __METHOD__ . "() given directory is unreadable: '$dir'\n" );
+
return null; // bad permissions?
}
+
return new FSFileBackendFileList( $dir, $params );
}
@@ -745,6 +775,7 @@ class FSFileBackend extends FileBackendStore {
public function handleWarning( $errno, $errstr ) {
wfDebugLog( 'FSFileBackend', $errstr ); // more detailed error logging
$this->hadWarningErrors[count( $this->hadWarningErrors ) - 1] = true;
+
return true; // suppress from PHP handler
}
}
@@ -823,6 +854,7 @@ abstract class FSFileBackendList implements Iterator {
# RecursiveDirectoryIterator extends FilesystemIterator.
# FilesystemIterator::SKIP_DOTS default is inconsistent in PHP 5.3.x.
$flags = FilesystemIterator::CURRENT_AS_SELF | FilesystemIterator::SKIP_DOTS;
+
return new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $dir, $flags ),
RecursiveIteratorIterator::CHILD_FIRST // include dirs
@@ -885,7 +917,8 @@ abstract class FSFileBackendList implements Iterator {
/**
* Filter out items by advancing to the next ones
*/
- protected function filterViaNext() {}
+ protected function filterViaNext() {
+ }
/**
* Return only the relative path and normalize slashes to FileBackend-style.
@@ -899,6 +932,7 @@ abstract class FSFileBackendList implements Iterator {
if ( $path === false ) {
$path = $dir;
}
+
return strtr( substr( $path, $this->suffixStart ), '\\', '/' );
}
}
diff --git a/includes/filebackend/FileBackend.php b/includes/filebackend/FileBackend.php
index 4bcaa7f840d7..0f449766c01f 100644
--- a/includes/filebackend/FileBackend.php
+++ b/includes/filebackend/FileBackend.php
@@ -809,10 +809,11 @@ abstract class FileBackend {
final protected function getScopedPHPBehaviorForOps() {
if ( PHP_SAPI != 'cli' ) { // http://bugs.php.net/bug.php?id=47540
$old = ignore_user_abort( true ); // avoid half-finished operations
- return new ScopedCallback( function() use ( $old ) {
+ return new ScopedCallback( function () use ( $old ) {
ignore_user_abort( $old );
} );
}
+
return null;
}
@@ -1137,7 +1138,8 @@ abstract class FileBackend {
* @param array $paths Storage paths
* @return void
*/
- public function preloadCache( array $paths ) {}
+ public function preloadCache( array $paths ) {
+ }
/**
* Invalidate any in-process file stat and property cache.
@@ -1146,7 +1148,8 @@ abstract class FileBackend {
* @param array $paths Storage paths (optional)
* @return void
*/
- public function clearCache( array $paths = null ) {}
+ public function clearCache( array $paths = null ) {
+ }
/**
* Lock the files at the given storage paths in the backend.
@@ -1160,6 +1163,7 @@ abstract class FileBackend {
*/
final public function lockFiles( array $paths, $type ) {
$paths = array_map( 'FileBackend::normalizeStoragePath', $paths );
+
return $this->lockManager->lock( $paths, $type );
}
@@ -1172,6 +1176,7 @@ abstract class FileBackend {
*/
final public function unlockFiles( array $paths, $type ) {
$paths = array_map( 'FileBackend::normalizeStoragePath', $paths );
+
return $this->lockManager->unlock( $paths, $type );
}
@@ -1198,6 +1203,7 @@ abstract class FileBackend {
} else {
$paths = array_map( 'FileBackend::normalizeStoragePath', $paths );
}
+
return ScopedLock::factory( $this->lockManager, $paths, $type, $status );
}
@@ -1281,6 +1287,7 @@ abstract class FileBackend {
}
}
}
+
return array( null, null, null );
}
@@ -1301,6 +1308,7 @@ abstract class FileBackend {
: "mwstore://{$backend}/{$container}";
}
}
+
return null;
}
@@ -1315,6 +1323,7 @@ abstract class FileBackend {
final public static function parentStoragePath( $storagePath ) {
$storagePath = dirname( $storagePath );
list( , , $rel ) = self::splitStoragePath( $storagePath );
+
return ( $rel === null ) ? null : $storagePath;
}
@@ -1326,6 +1335,7 @@ abstract class FileBackend {
*/
final public static function extensionFromPath( $path ) {
$i = strrpos( $path, '.' );
+
return strtolower( $i ? substr( $path, $i + 1 ) : '' );
}
@@ -1395,6 +1405,7 @@ abstract class FileBackend {
return null;
}
}
+
return $path;
}
}
@@ -1403,4 +1414,5 @@ abstract class FileBackend {
* @ingroup FileBackend
* @since 1.22
*/
-class FileBackendError extends MWException {}
+class FileBackendError extends MWException {
+}
diff --git a/includes/filebackend/FileBackendGroup.php b/includes/filebackend/FileBackendGroup.php
index be8a207633c2..e378d3ce583d 100644
--- a/includes/filebackend/FileBackendGroup.php
+++ b/includes/filebackend/FileBackendGroup.php
@@ -37,7 +37,8 @@ class FileBackendGroup {
/** @var Array (name => ('class' => string, 'config' => array, 'instance' => object)) */
protected $backends = array();
- protected function __construct() {}
+ protected function __construct() {
+ }
/**
* @return FileBackendGroup
@@ -47,6 +48,7 @@ class FileBackendGroup {
self::$instance = new self();
self::$instance->initFromGlobals();
}
+
return self::$instance;
}
@@ -159,6 +161,7 @@ class FileBackendGroup {
$config = $this->backends[$name]['config'];
$this->backends[$name]['instance'] = new $class( $config );
}
+
return $this->backends[$name]['instance'];
}
@@ -174,6 +177,7 @@ class FileBackendGroup {
throw new MWException( "No backend defined with the name `$name`." );
}
$class = $this->backends[$name]['class'];
+
return array( 'class' => $class ) + $this->backends[$name]['config'];
}
@@ -188,6 +192,7 @@ class FileBackendGroup {
if ( $backend !== null && isset( $this->backends[$backend] ) ) {
return $this->get( $backend );
}
+
return null;
}
}
diff --git a/includes/filebackend/FileBackendMultiWrite.php b/includes/filebackend/FileBackendMultiWrite.php
index 97584a7169dc..6af5398dab1e 100644
--- a/includes/filebackend/FileBackendMultiWrite.php
+++ b/includes/filebackend/FileBackendMultiWrite.php
@@ -167,6 +167,7 @@ class FileBackendMultiWrite extends FileBackend {
// Try to resync the clone backends to the master on the spot...
if ( !$this->autoResync || !$this->resyncFiles( $relevantPaths )->isOK() ) {
$status->merge( $syncStatus );
+
return $status; // abort
}
}
@@ -321,8 +322,8 @@ class FileBackendMultiWrite extends FileBackend {
// already synced; nothing to do
} elseif ( $mSha1 !== false ) { // file is in master
if ( $this->autoResync === 'conservative'
- && $cStat && $cStat['mtime'] > $mStat['mtime'] )
- {
+ && $cStat && $cStat['mtime'] > $mStat['mtime']
+ ) {
$status->fatal( 'backend-fail-synced', $path );
continue; // don't rollback data
}
@@ -357,8 +358,8 @@ class FileBackendMultiWrite extends FileBackend {
// For things like copy/move/delete with "ignoreMissingSource" and there
// is no source file, nothing should happen and there should be no errors.
if ( empty( $op['ignoreMissingSource'] )
- || $this->fileExists( array( 'src' => $op['src'] ) ) )
- {
+ || $this->fileExists( array( 'src' => $op['src'] ) )
+ ) {
$paths[] = $op['src'];
}
}
@@ -369,6 +370,7 @@ class FileBackendMultiWrite extends FileBackend {
$paths[] = $op['dst'];
}
}
+
return array_values( array_unique( array_filter( $paths, 'FileBackend::isStoragePath' ) ) );
}
@@ -391,6 +393,7 @@ class FileBackendMultiWrite extends FileBackend {
}
$newOps[] = $newOp;
}
+
return $newOps;
}
@@ -403,6 +406,7 @@ class FileBackendMultiWrite extends FileBackend {
*/
protected function substOpPaths( array $ops, FileBackendStore $backend ) {
$newOps = $this->substOpBatchPaths( array( $ops ), $backend );
+
return $newOps[0];
}
@@ -456,6 +460,7 @@ class FileBackendMultiWrite extends FileBackend {
$status->success = $masterStatus->success;
$status->successCount = $masterStatus->successCount;
$status->failCount = $masterStatus->failCount;
+
return $status;
}
@@ -465,6 +470,7 @@ class FileBackendMultiWrite extends FileBackend {
*/
protected function replicateContainerDirChanges( $path ) {
list( , $shortCont, ) = self::splitStoragePath( $path );
+
return !in_array( $shortCont, $this->noPushDirConts );
}
@@ -477,6 +483,7 @@ class FileBackendMultiWrite extends FileBackend {
$status->merge( $backend->doPrepare( $realParams ) );
}
}
+
return $status;
}
@@ -489,6 +496,7 @@ class FileBackendMultiWrite extends FileBackend {
$status->merge( $backend->doSecure( $realParams ) );
}
}
+
return $status;
}
@@ -501,6 +509,7 @@ class FileBackendMultiWrite extends FileBackend {
$status->merge( $backend->doPublish( $realParams ) );
}
}
+
return $status;
}
@@ -513,32 +522,38 @@ class FileBackendMultiWrite extends FileBackend {
$status->merge( $backend->doClean( $realParams ) );
}
}
+
return $status;
}
public function concatenate( array $params ) {
// We are writing to an FS file, so we don't need to do this per-backend
$realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
+
return $this->backends[$this->masterIndex]->concatenate( $realParams );
}
public function fileExists( array $params ) {
$realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
+
return $this->backends[$this->masterIndex]->fileExists( $realParams );
}
public function getFileTimestamp( array $params ) {
$realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
+
return $this->backends[$this->masterIndex]->getFileTimestamp( $realParams );
}
public function getFileSize( array $params ) {
$realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
+
return $this->backends[$this->masterIndex]->getFileSize( $realParams );
}
public function getFileStat( array $params ) {
$realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
+
return $this->backends[$this->masterIndex]->getFileStat( $realParams );
}
@@ -550,21 +565,25 @@ class FileBackendMultiWrite extends FileBackend {
foreach ( $contentsM as $path => $data ) {
$contents[$this->unsubstPaths( $path )] = $data;
}
+
return $contents;
}
public function getFileSha1Base36( array $params ) {
$realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
+
return $this->backends[$this->masterIndex]->getFileSha1Base36( $realParams );
}
public function getFileProps( array $params ) {
$realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
+
return $this->backends[$this->masterIndex]->getFileProps( $realParams );
}
public function streamFile( array $params ) {
$realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
+
return $this->backends[$this->masterIndex]->streamFile( $realParams );
}
@@ -576,6 +595,7 @@ class FileBackendMultiWrite extends FileBackend {
foreach ( $fsFilesM as $path => $fsFile ) {
$fsFiles[$this->unsubstPaths( $path )] = $fsFile;
}
+
return $fsFiles;
}
@@ -587,26 +607,31 @@ class FileBackendMultiWrite extends FileBackend {
foreach ( $tempFilesM as $path => $tempFile ) {
$tempFiles[$this->unsubstPaths( $path )] = $tempFile;
}
+
return $tempFiles;
}
public function getFileHttpUrl( array $params ) {
$realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
+
return $this->backends[$this->masterIndex]->getFileHttpUrl( $realParams );
}
public function directoryExists( array $params ) {
$realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
+
return $this->backends[$this->masterIndex]->directoryExists( $realParams );
}
public function getDirectoryList( array $params ) {
$realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
+
return $this->backends[$this->masterIndex]->getDirectoryList( $realParams );
}
public function getFileList( array $params ) {
$realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
+
return $this->backends[$this->masterIndex]->getFileList( $realParams );
}
@@ -627,6 +652,7 @@ class FileBackendMultiWrite extends FileBackend {
LockManager::LOCK_UW => $this->unsubstPaths( $paths[LockManager::LOCK_UW] ),
LockManager::LOCK_EX => $this->unsubstPaths( $paths[LockManager::LOCK_EX] )
);
+
// Actually acquire the locks
return array( $this->getScopedFileLocks( $pbPaths, 'mixed', $status ) );
}
diff --git a/includes/filebackend/FileBackendStore.php b/includes/filebackend/FileBackendStore.php
index eaa653d2b03b..d1e96bca4a9d 100644
--- a/includes/filebackend/FileBackendStore.php
+++ b/includes/filebackend/FileBackendStore.php
@@ -68,9 +68,9 @@ abstract class FileBackendStore extends FileBackend {
parent::__construct( $config );
$this->mimeCallback = isset( $config['mimeCallback'] )
? $config['mimeCallback']
- : function( $storagePath, $content, $fsPath ) {
+ : function ( $storagePath, $content, $fsPath ) {
// @TODO: handle the case of extension-less files using the contents
- return StreamFile::contentTypeFromPath( $storagePath ) ?: 'unknown/unknown';
+ return StreamFile::contentTypeFromPath( $storagePath ) ? : 'unknown/unknown';
};
$this->memCache = new EmptyBagOStuff(); // disabled by default
$this->cheapCache = new ProcessCacheLRU( self::CACHE_CHEAP_SIZE );
@@ -129,6 +129,7 @@ abstract class FileBackendStore extends FileBackend {
$this->deleteFileCache( $params['dst'] ); // persistent cache
}
}
+
return $status;
}
@@ -168,6 +169,7 @@ abstract class FileBackendStore extends FileBackend {
$this->deleteFileCache( $params['dst'] ); // persistent cache
}
}
+
return $status;
}
@@ -203,6 +205,7 @@ abstract class FileBackendStore extends FileBackend {
if ( !isset( $params['dstExists'] ) || $params['dstExists'] ) {
$this->deleteFileCache( $params['dst'] ); // persistent cache
}
+
return $status;
}
@@ -267,6 +270,7 @@ abstract class FileBackendStore extends FileBackend {
if ( !isset( $params['dstExists'] ) || $params['dstExists'] ) {
$this->deleteFileCache( $params['dst'] ); // persistent cache
}
+
return $status;
}
@@ -285,6 +289,7 @@ abstract class FileBackendStore extends FileBackend {
$status->merge( $this->deleteInternal( array( 'src' => $params['src'] ) ) );
$status->setResult( true, $status->value ); // ignore delete() errors
}
+
return $status;
}
@@ -311,6 +316,7 @@ abstract class FileBackendStore extends FileBackend {
} else {
$status = Status::newGood(); // nothing to do
}
+
return $status;
}
@@ -368,6 +374,7 @@ abstract class FileBackendStore extends FileBackend {
wfRestoreWarnings();
if ( !$ok ) { // not present or not empty
$status->fatal( 'backend-fail-opentemp', $tmpPath );
+
return $status;
}
@@ -378,6 +385,7 @@ abstract class FileBackendStore extends FileBackend {
$fsFile = $this->getLocalReference( array( 'src' => $path ) );
if ( !$fsFile ) { // retry failed?
$status->fatal( 'backend-fail-read', $path );
+
return $status;
}
}
@@ -388,6 +396,7 @@ abstract class FileBackendStore extends FileBackend {
$tmpHandle = fopen( $tmpPath, 'ab' );
if ( $tmpHandle === false ) {
$status->fatal( 'backend-fail-opentemp', $tmpPath );
+
return $status;
}
@@ -398,6 +407,7 @@ abstract class FileBackendStore extends FileBackend {
if ( $sourceHandle === false ) {
fclose( $tmpHandle );
$status->fatal( 'backend-fail-read', $virtualSource );
+
return $status;
}
// Append chunk to file (pass chunk size to avoid magic quotes)
@@ -405,12 +415,14 @@ abstract class FileBackendStore extends FileBackend {
fclose( $sourceHandle );
fclose( $tmpHandle );
$status->fatal( 'backend-fail-writetemp', $tmpPath );
+
return $status;
}
fclose( $sourceHandle );
}
if ( !fclose( $tmpHandle ) ) {
$status->fatal( 'backend-fail-closetemp', $tmpPath );
+
return $status;
}
@@ -426,6 +438,7 @@ abstract class FileBackendStore extends FileBackend {
list( $fullCont, $dir, $shard ) = $this->resolveStoragePath( $params['dir'] );
if ( $dir === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['dir'] );
+
return $status; // invalid storage path
}
@@ -457,6 +470,7 @@ abstract class FileBackendStore extends FileBackend {
list( $fullCont, $dir, $shard ) = $this->resolveStoragePath( $params['dir'] );
if ( $dir === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['dir'] );
+
return $status; // invalid storage path
}
@@ -488,6 +502,7 @@ abstract class FileBackendStore extends FileBackend {
list( $fullCont, $dir, $shard ) = $this->resolveStoragePath( $params['dir'] );
if ( $dir === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['dir'] );
+
return $status; // invalid storage path
}
@@ -531,6 +546,7 @@ abstract class FileBackendStore extends FileBackend {
list( $fullCont, $dir, $shard ) = $this->resolveStoragePath( $params['dir'] );
if ( $dir === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['dir'] );
+
return $status; // invalid storage path
}
@@ -567,18 +583,21 @@ abstract class FileBackendStore extends FileBackend {
final public function fileExists( array $params ) {
$section = new ProfileSection( __METHOD__ . "-{$this->name}" );
$stat = $this->getFileStat( $params );
+
return ( $stat === null ) ? null : (bool)$stat; // null => failure
}
final public function getFileTimestamp( array $params ) {
$section = new ProfileSection( __METHOD__ . "-{$this->name}" );
$stat = $this->getFileStat( $params );
+
return $stat ? $stat['mtime'] : false;
}
final public function getFileSize( array $params ) {
$section = new ProfileSection( __METHOD__ . "-{$this->name}" );
$stat = $this->getFileStat( $params );
+
return $stat ? $stat['size'] : false;
}
@@ -625,6 +644,7 @@ abstract class FileBackendStore extends FileBackend {
} else { // an error occurred
wfDebug( __METHOD__ . ": Could not stat file $path.\n" );
}
+
return $stat;
}
@@ -653,6 +673,7 @@ abstract class FileBackendStore extends FileBackend {
$contents[$path] = $fsFile ? file_get_contents( $fsFile->getPath() ) : false;
wfRestoreWarnings();
}
+
return $contents;
}
@@ -675,6 +696,7 @@ abstract class FileBackendStore extends FileBackend {
$hash = $this->doGetFileSha1Base36( $params );
wfProfileOut( __METHOD__ . '-miss-' . $this->name );
$this->cheapCache->set( $path, 'sha1', array( 'hash' => $hash, 'latest' => $latest ) );
+
return $hash;
}
@@ -695,6 +717,7 @@ abstract class FileBackendStore extends FileBackend {
$section = new ProfileSection( __METHOD__ . "-{$this->name}" );
$fsFile = $this->getLocalReference( $params );
$props = $fsFile ? $fsFile->getProps() : FSFile::placeholderProps();
+
return $props;
}
@@ -833,6 +856,7 @@ abstract class FileBackendStore extends FileBackend {
$res = null; // if we don't find anything, it is indeterminate
}
}
+
return $res;
}
}
@@ -859,6 +883,7 @@ abstract class FileBackendStore extends FileBackend {
wfDebug( __METHOD__ . ": iterating over all container shards.\n" );
// File listing spans multiple containers/shards
list( , $shortCont, ) = self::splitStoragePath( $params['dir'] );
+
return new FileBackendStoreShardDirIterator( $this,
$fullCont, $dir, $this->getContainerSuffixes( $shortCont ), $params );
}
@@ -888,6 +913,7 @@ abstract class FileBackendStore extends FileBackend {
wfDebug( __METHOD__ . ": iterating over all container shards.\n" );
// File listing spans multiple containers/shards
list( , $shortCont, ) = self::splitStoragePath( $params['dir'] );
+
return new FileBackendStoreShardFileIterator( $this,
$fullCont, $dir, $this->getContainerSuffixes( $shortCont ), $params );
}
@@ -975,6 +1001,7 @@ abstract class FileBackendStore extends FileBackend {
public function getScopedLocksForOps( array $ops, Status $status ) {
$paths = $this->getPathsToLockForOpsInternal( $this->getOperationsInternal( $ops ) );
+
return array( $this->getScopedFileLocks( $paths, 'mixed', $status ) );
}
@@ -1097,6 +1124,7 @@ abstract class FileBackendStore extends FileBackend {
foreach ( $fileOpHandles as $fileOpHandle ) {
$fileOpHandle->closeResources();
}
+
return $res;
}
@@ -1110,6 +1138,7 @@ abstract class FileBackendStore extends FileBackend {
foreach ( $fileOpHandles as $fileOpHandle ) { // OK if empty
throw new MWException( "This backend supports no asynchronous operations." );
}
+
return array();
}
@@ -1135,6 +1164,7 @@ abstract class FileBackendStore extends FileBackend {
}
}
}
+
return $op;
}
@@ -1174,7 +1204,8 @@ abstract class FileBackendStore extends FileBackend {
* @param array $paths Storage paths (optional)
* @return void
*/
- protected function doClearCache( array $paths = null ) {}
+ protected function doClearCache( array $paths = null ) {
+ }
/**
* Is this a key/value store where directories are just virtual?
@@ -1236,6 +1267,7 @@ abstract class FileBackendStore extends FileBackend {
}
}
}
+
return array( null, null, null );
}
@@ -1259,6 +1291,7 @@ abstract class FileBackendStore extends FileBackend {
if ( $cShard !== null && substr( $relPath, -1 ) !== '/' ) {
return array( $container, $relPath );
}
+
return array( null, null );
}
@@ -1293,8 +1326,10 @@ abstract class FileBackendStore extends FileBackend {
if ( preg_match( "!^(?:[^/]{2,}/)*$hashDirRegex(?:/|$)!", $relPath, $m ) ) {
return '.' . implode( '', array_slice( $m, 1 ) );
}
+
return null; // failed to match
}
+
return ''; // no sharding
}
@@ -1308,6 +1343,7 @@ abstract class FileBackendStore extends FileBackend {
*/
final public function isSingleShardPathInternal( $storagePath ) {
list( , , $shard ) = $this->resolveStoragePath( $storagePath );
+
return ( $shard !== null );
}
@@ -1330,6 +1366,7 @@ abstract class FileBackendStore extends FileBackend {
}
}
}
+
return array( 0, 0, false ); // no sharding
}
@@ -1348,6 +1385,7 @@ abstract class FileBackendStore extends FileBackend {
$shards[] = '.' . wfBaseConvert( $index, 10, $base, $digits );
}
}
+
return $shards;
}
@@ -1476,7 +1514,8 @@ abstract class FileBackendStore extends FileBackend {
* @param array $containerInfo Map of resolved container names to cached info
* @return void
*/
- protected function doPrimeContainerCache( array $containerInfo ) {}
+ protected function doPrimeContainerCache( array $containerInfo ) {
+ }
/**
* Get the cache key for a file path
@@ -1588,6 +1627,7 @@ abstract class FileBackendStore extends FileBackend {
$opts['concurrency'] = $this->concurrency;
}
}
+
return $opts;
}
@@ -1683,6 +1723,7 @@ abstract class FileBackendStoreShardListIterator extends FilterIterator {
return false;
} else {
$this->multiShardPaths[$rel] = 1;
+
return true;
}
}
diff --git a/includes/filebackend/FileOp.php b/includes/filebackend/FileOp.php
index 05c0a39b1c28..c910399d917f 100644
--- a/includes/filebackend/FileOp.php
+++ b/includes/filebackend/FileOp.php
@@ -93,8 +93,10 @@ abstract class FileOp {
protected static function normalizeIfValidStoragePath( $path ) {
if ( FileBackend::isStoragePath( $path ) ) {
$res = FileBackend::normalizeStoragePath( $path );
+
return ( $res !== null ) ? $res : $path;
}
+
return $path;
}
@@ -154,6 +156,7 @@ abstract class FileOp {
final public function applyDependencies( array $deps ) {
$deps['read'] += array_fill_keys( $this->storagePathsRead(), 1 );
$deps['write'] += array_fill_keys( $this->storagePathsChanged(), 1 );
+
return $deps;
}
@@ -174,6 +177,7 @@ abstract class FileOp {
return true; // "flow" dependency
}
}
+
return false;
}
@@ -214,6 +218,7 @@ abstract class FileOp {
);
}
}
+
return array_merge( $nullEntries, $updateEntries, $deleteEntries );
}
@@ -234,6 +239,7 @@ abstract class FileOp {
if ( !$status->isOK() ) {
$this->failed = true;
}
+
return $status;
}
@@ -265,6 +271,7 @@ abstract class FileOp {
} else { // no-op
$status = Status::newGood();
}
+
return $status;
}
@@ -284,6 +291,7 @@ abstract class FileOp {
$this->async = true;
$result = $this->attempt();
$this->async = false;
+
return $result;
}
@@ -355,12 +363,15 @@ abstract class FileOp {
} else {
$this->overwriteSameCase = true; // OK
}
+
return $status; // do nothing; either OK or bad status
} else {
$status->fatal( 'backend-fail-alreadyexists', $this->params['dst'] );
+
return $status;
}
}
+
return $status;
}
@@ -386,6 +397,7 @@ abstract class FileOp {
return $predicates['exists'][$source]; // previous op assures this
} else {
$params = array( 'src' => $source, 'latest' => true );
+
return $this->backend->fileExists( $params );
}
}
@@ -404,6 +416,7 @@ abstract class FileOp {
return false; // previous op assures this
} else {
$params = array( 'src' => $source, 'latest' => true );
+
return $this->backend->getFileSha1Base36( $params );
}
}
@@ -455,11 +468,13 @@ class CreateFileOp extends FileOp {
$status->fatal( 'backend-fail-maxsize',
$this->params['dst'], $this->backend->maxFileSizeInternal() );
$status->fatal( 'backend-fail-create', $this->params['dst'] );
+
return $status;
// Check if a file can be placed/changed at the destination
} elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
$status->fatal( 'backend-fail-usable', $this->params['dst'] );
$status->fatal( 'backend-fail-create', $this->params['dst'] );
+
return $status;
}
// Check if destination file exists
@@ -470,6 +485,7 @@ class CreateFileOp extends FileOp {
$predicates['exists'][$this->params['dst']] = true;
$predicates['sha1'][$this->params['dst']] = $this->sourceSha1;
}
+
return $status; // safe to call attempt()
}
@@ -478,6 +494,7 @@ class CreateFileOp extends FileOp {
// Create the file at the destination
return $this->backend->createInternal( $this->setFlags( $this->params ) );
}
+
return Status::newGood();
}
@@ -508,17 +525,20 @@ class StoreFileOp extends FileOp {
// Check if the source file exists on the file system
if ( !is_file( $this->params['src'] ) ) {
$status->fatal( 'backend-fail-notexists', $this->params['src'] );
+
return $status;
// Check if the source file is too big
} elseif ( filesize( $this->params['src'] ) > $this->backend->maxFileSizeInternal() ) {
$status->fatal( 'backend-fail-maxsize',
$this->params['dst'], $this->backend->maxFileSizeInternal() );
$status->fatal( 'backend-fail-store', $this->params['src'], $this->params['dst'] );
+
return $status;
// Check if a file can be placed/changed at the destination
} elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
$status->fatal( 'backend-fail-usable', $this->params['dst'] );
$status->fatal( 'backend-fail-store', $this->params['src'], $this->params['dst'] );
+
return $status;
}
// Check if destination file exists
@@ -529,6 +549,7 @@ class StoreFileOp extends FileOp {
$predicates['exists'][$this->params['dst']] = true;
$predicates['sha1'][$this->params['dst']] = $this->sourceSha1;
}
+
return $status; // safe to call attempt()
}
@@ -537,6 +558,7 @@ class StoreFileOp extends FileOp {
// Store the file at the destination
return $this->backend->storeInternal( $this->setFlags( $this->params ) );
}
+
return Status::newGood();
}
@@ -547,6 +569,7 @@ class StoreFileOp extends FileOp {
if ( $hash !== false ) {
$hash = wfBaseConvert( $hash, 16, 36, 31 );
}
+
return $hash;
}
@@ -577,15 +600,18 @@ class CopyFileOp extends FileOp {
// Update file existence predicates (cache 404s)
$predicates['exists'][$this->params['src']] = false;
$predicates['sha1'][$this->params['src']] = false;
+
return $status; // nothing to do
} else {
$status->fatal( 'backend-fail-notexists', $this->params['src'] );
+
return $status;
}
- // Check if a file can be placed/changed at the destination
+ // Check if a file can be placed/changed at the destination
} elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
$status->fatal( 'backend-fail-usable', $this->params['dst'] );
$status->fatal( 'backend-fail-copy', $this->params['src'], $this->params['dst'] );
+
return $status;
}
// Check if destination file exists
@@ -596,6 +622,7 @@ class CopyFileOp extends FileOp {
$predicates['exists'][$this->params['dst']] = true;
$predicates['sha1'][$this->params['dst']] = $this->sourceSha1;
}
+
return $status; // safe to call attempt()
}
@@ -604,7 +631,7 @@ class CopyFileOp extends FileOp {
$status = Status::newGood(); // nothing to do
} elseif ( $this->params['src'] === $this->params['dst'] ) {
// Just update the destination file headers
- $headers = $this->getParam( 'headers' ) ?: array();
+ $headers = $this->getParam( 'headers' ) ? : array();
$status = $this->backend->describeInternal( $this->setFlags( array(
'src' => $this->params['dst'], 'headers' => $headers
) ) );
@@ -612,6 +639,7 @@ class CopyFileOp extends FileOp {
// Copy the file to the destination
$status = $this->backend->copyInternal( $this->setFlags( $this->params ) );
}
+
return $status;
}
@@ -646,15 +674,18 @@ class MoveFileOp extends FileOp {
// Update file existence predicates (cache 404s)
$predicates['exists'][$this->params['src']] = false;
$predicates['sha1'][$this->params['src']] = false;
+
return $status; // nothing to do
} else {
$status->fatal( 'backend-fail-notexists', $this->params['src'] );
+
return $status;
}
// Check if a file can be placed/changed at the destination
} elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
$status->fatal( 'backend-fail-usable', $this->params['dst'] );
$status->fatal( 'backend-fail-move', $this->params['src'], $this->params['dst'] );
+
return $status;
}
// Check if destination file exists
@@ -667,6 +698,7 @@ class MoveFileOp extends FileOp {
$predicates['exists'][$this->params['dst']] = true;
$predicates['sha1'][$this->params['dst']] = $this->sourceSha1;
}
+
return $status; // safe to call attempt()
}
@@ -691,6 +723,7 @@ class MoveFileOp extends FileOp {
// Move the file to the destination
$status = $this->backend->moveInternal( $this->setFlags( $this->params ) );
}
+
return $status;
}
@@ -721,20 +754,24 @@ class DeleteFileOp extends FileOp {
// Update file existence predicates (cache 404s)
$predicates['exists'][$this->params['src']] = false;
$predicates['sha1'][$this->params['src']] = false;
+
return $status; // nothing to do
} else {
$status->fatal( 'backend-fail-notexists', $this->params['src'] );
+
return $status;
}
// Check if a file can be placed/changed at the source
} elseif ( !$this->backend->isPathUsableInternal( $this->params['src'] ) ) {
$status->fatal( 'backend-fail-usable', $this->params['src'] );
$status->fatal( 'backend-fail-delete', $this->params['src'] );
+
return $status;
}
// Update file existence predicates
$predicates['exists'][$this->params['src']] = false;
$predicates['sha1'][$this->params['src']] = false;
+
return $status; // safe to call attempt()
}
@@ -762,11 +799,13 @@ class DescribeFileOp extends FileOp {
// Check if the source file exists
if ( !$this->fileExists( $this->params['src'], $predicates ) ) {
$status->fatal( 'backend-fail-notexists', $this->params['src'] );
+
return $status;
// Check if a file can be placed/changed at the source
} elseif ( !$this->backend->isPathUsableInternal( $this->params['src'] ) ) {
$status->fatal( 'backend-fail-usable', $this->params['src'] );
$status->fatal( 'backend-fail-describe', $this->params['src'] );
+
return $status;
}
// Update file existence predicates
@@ -774,6 +813,7 @@ class DescribeFileOp extends FileOp {
$this->fileExists( $this->params['src'], $predicates );
$predicates['sha1'][$this->params['src']] =
$this->fileSha1( $this->params['src'], $predicates );
+
return $status; // safe to call attempt()
}
@@ -790,4 +830,5 @@ class DescribeFileOp extends FileOp {
/**
* Placeholder operation that has no params and does nothing
*/
-class NullFileOp extends FileOp {}
+class NullFileOp extends FileOp {
+}
diff --git a/includes/filebackend/FileOpBatch.php b/includes/filebackend/FileOpBatch.php
index 785c0bc92514..d90b393ff028 100644
--- a/includes/filebackend/FileOpBatch.php
+++ b/includes/filebackend/FileOpBatch.php
@@ -62,6 +62,7 @@ class FileOpBatch {
if ( $n > self::MAX_BATCH_SIZE ) {
$status->fatal( 'backend-fail-batchsize', $n, self::MAX_BATCH_SIZE );
wfProfileOut( __METHOD__ );
+
return $status;
}
@@ -108,6 +109,7 @@ class FileOpBatch {
++$status->failCount;
if ( !$ignoreErrors ) {
wfProfileOut( __METHOD__ );
+
return $status; // abort
}
}
@@ -122,6 +124,7 @@ class FileOpBatch {
$subStatus = $journal->logChangeBatch( $entries, $batchId );
if ( !$subStatus->isOK() ) {
wfProfileOut( __METHOD__ );
+
return $subStatus; // abort
}
}
@@ -134,6 +137,7 @@ class FileOpBatch {
self::runParallelBatches( $pPerformOps, $status );
wfProfileOut( __METHOD__ );
+
return $status;
}
@@ -199,6 +203,7 @@ class FileOpBatch {
}
}
}
+
return $status;
}
}
diff --git a/includes/filebackend/SwiftFileBackend.php b/includes/filebackend/SwiftFileBackend.php
index 1787d66f2cef..d46c66f0b473 100644
--- a/includes/filebackend/SwiftFileBackend.php
+++ b/includes/filebackend/SwiftFileBackend.php
@@ -153,7 +153,8 @@ class SwiftFileBackend extends FileBackendStore {
} else {
try { // look for APC, XCache, WinCache, ect...
$this->srvCache = ObjectCache::newAccelerator( array() );
- } catch ( Exception $e ) {}
+ } catch ( Exception $e ) {
+ }
}
}
$this->srvCache = $this->srvCache ? $this->srvCache : new EmptyBagOStuff();
@@ -169,6 +170,7 @@ class SwiftFileBackend extends FileBackendStore {
} elseif ( strlen( urlencode( $relStoragePath ) ) > 1024 ) {
return null; // too long for Swift
}
+
return $relStoragePath;
}
@@ -180,6 +182,7 @@ class SwiftFileBackend extends FileBackendStore {
try {
$this->getContainer( $container );
+
return true; // container exists
} catch ( NoSuchContainerException $e ) {
} catch ( CloudFilesException $e ) { // some other exception?
@@ -198,6 +201,7 @@ class SwiftFileBackend extends FileBackendStore {
if ( isset( $headers['Content-Disposition'] ) ) {
$headers['Content-Disposition'] = $this->truncDisp( $headers['Content-Disposition'] );
}
+
return $headers;
}
@@ -216,6 +220,7 @@ class SwiftFileBackend extends FileBackendStore {
break; // too long; sigh
}
}
+
return $res;
}
@@ -225,6 +230,7 @@ class SwiftFileBackend extends FileBackendStore {
list( $dstCont, $dstRel ) = $this->resolveStoragePathReal( $params['dst'] );
if ( $dstRel === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['dst'] );
+
return $status;
}
@@ -233,9 +239,11 @@ class SwiftFileBackend extends FileBackendStore {
$dContObj = $this->getContainer( $dstCont );
} catch ( NoSuchContainerException $e ) {
$status->fatal( 'backend-fail-create', $params['dst'] );
+
return $status;
} catch ( CloudFilesException $e ) { // some other exception?
$this->handleException( $e, $status, __METHOD__, $params );
+
return $status;
}
@@ -293,6 +301,7 @@ class SwiftFileBackend extends FileBackendStore {
list( $dstCont, $dstRel ) = $this->resolveStoragePathReal( $params['dst'] );
if ( $dstRel === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['dst'] );
+
return $status;
}
@@ -301,9 +310,11 @@ class SwiftFileBackend extends FileBackendStore {
$dContObj = $this->getContainer( $dstCont );
} catch ( NoSuchContainerException $e ) {
$status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
+
return $status;
} catch ( CloudFilesException $e ) { // some other exception?
$this->handleException( $e, $status, __METHOD__, $params );
+
return $status;
}
@@ -313,6 +324,7 @@ class SwiftFileBackend extends FileBackendStore {
wfRestoreWarnings();
if ( $sha1Hash === false ) { // source doesn't exist?
$status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
+
return $status;
}
$sha1Hash = wfBaseConvert( $sha1Hash, 16, 36, 31 );
@@ -379,12 +391,14 @@ class SwiftFileBackend extends FileBackendStore {
list( $srcCont, $srcRel ) = $this->resolveStoragePathReal( $params['src'] );
if ( $srcRel === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['src'] );
+
return $status;
}
list( $dstCont, $dstRel ) = $this->resolveStoragePathReal( $params['dst'] );
if ( $dstRel === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['dst'] );
+
return $status;
}
@@ -396,9 +410,11 @@ class SwiftFileBackend extends FileBackendStore {
if ( empty( $params['ignoreMissingSource'] ) || isset( $sContObj ) ) {
$status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
}
+
return $status;
} catch ( CloudFilesException $e ) { // some other exception?
$this->handleException( $e, $status, __METHOD__, $params );
+
return $status;
}
@@ -448,12 +464,14 @@ class SwiftFileBackend extends FileBackendStore {
list( $srcCont, $srcRel ) = $this->resolveStoragePathReal( $params['src'] );
if ( $srcRel === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['src'] );
+
return $status;
}
list( $dstCont, $dstRel ) = $this->resolveStoragePathReal( $params['dst'] );
if ( $dstRel === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['dst'] );
+
return $status;
}
@@ -465,9 +483,11 @@ class SwiftFileBackend extends FileBackendStore {
if ( empty( $params['ignoreMissingSource'] ) || isset( $sContObj ) ) {
$status->fatal( 'backend-fail-move', $params['src'], $params['dst'] );
}
+
return $status;
} catch ( CloudFilesException $e ) { // some other exception?
$this->handleException( $e, $status, __METHOD__, $params );
+
return $status;
}
@@ -520,6 +540,7 @@ class SwiftFileBackend extends FileBackendStore {
list( $srcCont, $srcRel ) = $this->resolveStoragePathReal( $params['src'] );
if ( $srcRel === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['src'] );
+
return $status;
}
@@ -572,6 +593,7 @@ class SwiftFileBackend extends FileBackendStore {
list( $srcCont, $srcRel ) = $this->resolveStoragePathReal( $params['src'] );
if ( $srcRel === null ) {
$status->fatal( 'backend-fail-invalidpath', $params['src'] );
+
return $status;
}
@@ -605,12 +627,14 @@ class SwiftFileBackend extends FileBackendStore {
// (a) Check if container already exists
try {
$this->getContainer( $fullCont );
+
// NoSuchContainerException not thrown: container must exist
return $status; // already exists
} catch ( NoSuchContainerException $e ) {
// NoSuchContainerException thrown: container does not exist
} catch ( CloudFilesException $e ) { // some other exception?
$this->handleException( $e, $status, __METHOD__, $params );
+
return $status;
}
@@ -631,6 +655,7 @@ class SwiftFileBackend extends FileBackendStore {
// CDN not enabled; nothing to see here
} catch ( CloudFilesException $e ) { // some other exception?
$this->handleException( $e, $status, __METHOD__, $params );
+
return $status;
}
@@ -727,6 +752,7 @@ class SwiftFileBackend extends FileBackendStore {
return $status; // ok, nothing to do
} catch ( CloudFilesException $e ) { // some other exception?
$this->handleException( $e, $status, __METHOD__, $params );
+
return $status;
}
@@ -740,6 +766,7 @@ class SwiftFileBackend extends FileBackendStore {
return $status; // race? consistency delay?
} catch ( CloudFilesException $e ) { // some other exception?
$this->handleException( $e, $status, __METHOD__, $params );
+
return $status;
}
}
@@ -786,6 +813,7 @@ class SwiftFileBackend extends FileBackendStore {
*/
protected function convertSwiftDate( $ts, $format = TS_MW ) {
$timestamp = new MWTimestamp( $ts );
+
return $timestamp->getTimestamp( $format );
}
@@ -813,6 +841,7 @@ class SwiftFileBackend extends FileBackendStore {
$obj->setMetadataValues( array( 'Sha1base36' => $hash ) );
$obj->sync_metadata(); // save to Swift
wfProfileOut( __METHOD__ );
+
return true; // success
}
}
@@ -820,6 +849,7 @@ class SwiftFileBackend extends FileBackendStore {
trigger_error( "Unable to set SHA-1 metadata for $path", E_USER_WARNING );
$obj->setMetadataValues( array( 'Sha1base36' => false ) );
wfProfileOut( __METHOD__ );
+
return false; // failed
}
@@ -899,6 +929,7 @@ class SwiftFileBackend extends FileBackendStore {
try {
$container = $this->getContainer( $fullCont );
$prefix = ( $dir == '' ) ? null : "{$dir}/";
+
return ( count( $container->list_objects( 1, null, $prefix ) ) > 0 );
} catch ( NoSuchContainerException $e ) {
return false;
@@ -1075,8 +1106,8 @@ class SwiftFileBackend extends FileBackendStore {
if ( is_object( $object ) ) {
$stat = array(
// Convert various random Swift dates to TS_MW
- 'mtime' => $this->convertSwiftDate( $object->last_modified, TS_MW ),
- 'size' => (int)$object->content_length,
+ 'mtime' => $this->convertSwiftDate( $object->last_modified, TS_MW ),
+ 'size' => (int)$object->content_length,
'latest' => false // eventually consistent
);
$names[] = array( $object->name, $stat );
@@ -1085,6 +1116,7 @@ class SwiftFileBackend extends FileBackendStore {
$names[] = array( $object, null );
}
}
+
return $names;
}
@@ -1107,6 +1139,7 @@ class SwiftFileBackend extends FileBackendStore {
$this->clearCache( array( $params['src'] ) );
$stat = $this->getFileStat( $params );
}
+
return $stat['sha1'];
} else {
return false;
@@ -1125,9 +1158,11 @@ class SwiftFileBackend extends FileBackendStore {
$cont = $this->getContainer( $srcCont );
} catch ( NoSuchContainerException $e ) {
$status->fatal( 'backend-fail-stream', $params['src'] );
+
return $status;
} catch ( CloudFilesException $e ) { // some other exception?
$this->handleException( $e, $status, __METHOD__, $params );
+
return $status;
}
@@ -1215,8 +1250,8 @@ class SwiftFileBackend extends FileBackendStore {
public function getFileHttpUrl( array $params ) {
if ( $this->swiftTempUrlKey != '' ||
- ( $this->rgwS3AccessKey != '' && $this->rgwS3SecretKey != '' ) )
- {
+ ( $this->rgwS3AccessKey != '' && $this->rgwS3SecretKey != '' )
+ ) {
list( $srcCont, $srcRel ) = $this->resolveStoragePathReal( $params['src'] );
if ( $srcRel === null ) {
return null; // invalid path
@@ -1239,6 +1274,7 @@ class SwiftFileBackend extends FileBackendStore {
$this->rgwS3SecretKey,
true // raw
) );
+
// See http://s3.amazonaws.com/doc/s3-developer-guide/RESTAuthentication.html.
// Note: adding a newline for empty CanonicalizedAmzHeaders does not work.
return wfAppendQuery(
@@ -1255,6 +1291,7 @@ class SwiftFileBackend extends FileBackendStore {
$this->handleException( $e, null, __METHOD__, $params );
}
}
+
return null;
}
@@ -1275,6 +1312,7 @@ class SwiftFileBackend extends FileBackendStore {
if ( !empty( $params['latest'] ) ) {
$hdrs[] = 'X-Newest: true';
}
+
return $hdrs;
}
@@ -1413,6 +1451,7 @@ class SwiftFileBackend extends FileBackendStore {
}
$this->conn = new CF_Connection( $this->auth );
}
+
return $this->conn;
}
@@ -1466,6 +1505,7 @@ class SwiftFileBackend extends FileBackendStore {
);
}
}
+
return $this->connContainerCache->get( $container, 'obj' );
}
@@ -1514,7 +1554,7 @@ class SwiftFileBackend extends FileBackendStore {
* This also sets the Status object to have a fatal error.
*
* @param Exception $e
- * @param Status $status|null
+ * @param Status $status null
* @param string $func
* @param array $params
* @return void
@@ -1664,7 +1704,7 @@ abstract class SwiftFileBackendList implements Iterator {
*
* @param string $container Resolved container name
* @param string $dir Resolved path relative to container
- * @param string $after|null
+ * @param string $after null
* @param integer $limit
* @param array $params
* @return Traversable|Array
@@ -1708,6 +1748,7 @@ class SwiftFileBackendFileList extends SwiftFileBackendList {
$storageDir = rtrim( $this->params['dir'], '/' );
$this->backend->loadListingStatInternal( "$storageDir/$relPath", $stat );
}
+
return $relPath;
}
diff --git a/includes/filebackend/TempFSFile.php b/includes/filebackend/TempFSFile.php
index 8266e4201e21..4d2639f99679 100644
--- a/includes/filebackend/TempFSFile.php
+++ b/includes/filebackend/TempFSFile.php
@@ -56,12 +56,14 @@ class TempFSFile extends FSFile {
}
if ( $attempt >= 5 ) {
wfProfileOut( __METHOD__ );
+
return null; // give up
}
}
$tmpFile = new self( $path );
$tmpFile->canDelete = true; // safely instantiated
wfProfileOut( __METHOD__ );
+
return $tmpFile;
}
@@ -75,6 +77,7 @@ class TempFSFile extends FSFile {
wfSuppressWarnings();
$ok = unlink( $this->path );
wfRestoreWarnings();
+
return $ok;
}
@@ -92,6 +95,7 @@ class TempFSFile extends FSFile {
}
$object->tempFSFileReferences[] = $this;
}
+
return $this;
}
@@ -102,6 +106,7 @@ class TempFSFile extends FSFile {
*/
public function preserve() {
$this->canDelete = false;
+
return $this;
}
@@ -112,6 +117,7 @@ class TempFSFile extends FSFile {
*/
public function autocollect() {
$this->canDelete = true;
+
return $this;
}
diff --git a/includes/filebackend/filejournal/DBFileJournal.php b/includes/filebackend/filejournal/DBFileJournal.php
index 9250aa5e0118..42f4f1a97378 100644
--- a/includes/filebackend/filejournal/DBFileJournal.php
+++ b/includes/filebackend/filejournal/DBFileJournal.php
@@ -56,6 +56,7 @@ class DBFileJournal extends FileJournal {
$dbw = $this->getMasterDB();
} catch ( DBError $e ) {
$status->fatal( 'filejournal-fail-dbconnect', $this->backend );
+
return $status;
}
@@ -80,6 +81,7 @@ class DBFileJournal extends FileJournal {
}
} catch ( DBError $e ) {
$status->fatal( 'filejournal-fail-dbquery', $this->backend );
+
return $status;
}
@@ -108,6 +110,7 @@ class DBFileJournal extends FileJournal {
$dbw = $this->getMasterDB();
$encTimestamp = $dbw->addQuotes( $dbw->timestamp( $time ) );
+
return $dbw->selectField( 'filejournal', 'fj_id',
array( 'fj_backend' => $this->backend, "fj_timestamp <= $encTimestamp" ),
__METHOD__,
@@ -179,6 +182,7 @@ class DBFileJournal extends FileJournal {
$this->dbw = $lb->getConnection( DB_MASTER, array(), $this->wiki );
$this->dbw->clearFlag( DBO_TRX );
}
+
return $this->dbw;
}
}
diff --git a/includes/filebackend/filejournal/FileJournal.php b/includes/filebackend/filejournal/FileJournal.php
index a1b7a4596183..fe36ff23ed9e 100644
--- a/includes/filebackend/filejournal/FileJournal.php
+++ b/includes/filebackend/filejournal/FileJournal.php
@@ -65,6 +65,7 @@ abstract class FileJournal {
throw new MWException( "Class given is not an instance of FileJournal." );
}
$jrn->backend = $backend;
+
return $jrn;
}
@@ -79,6 +80,7 @@ abstract class FileJournal {
$s .= mt_rand( 0, 2147483647 );
}
$s = wfBaseConvert( sha1( $s ), 16, 36, 31 );
+
return substr( wfBaseConvert( wfTimestamp( TS_MW ), 10, 36, 9 ) . $s, 0, 31 );
}
@@ -98,6 +100,7 @@ abstract class FileJournal {
if ( !count( $entries ) ) {
return Status::newGood();
}
+
return $this->doLogChangeBatch( $entries, $batchId );
}
@@ -154,7 +157,6 @@ abstract class FileJournal {
* path : affected storage path
* new_sha1 : base 36 sha1 of the new file had the operation succeeded
* timestamp : TS_MW timestamp of the batch change
-
* Also, $next is updated to the ID of the next entry.
*
* @param $start integer Starting change ID or null
@@ -170,6 +172,7 @@ abstract class FileJournal {
} else {
$next = null; // end of list
}
+
return $entries;
}
diff --git a/includes/filebackend/lockmanager/DBLockManager.php b/includes/filebackend/lockmanager/DBLockManager.php
index 3e934ba502f9..68d684e8512e 100644
--- a/includes/filebackend/lockmanager/DBLockManager.php
+++ b/includes/filebackend/lockmanager/DBLockManager.php
@@ -116,6 +116,7 @@ abstract class DBLockManager extends QuorumLockManager {
foreach ( $pathsByType as $type => $paths ) {
$status->merge( $this->doGetLocksOnServer( $lockSrv, $paths, $type ) );
}
+
return $status;
}
@@ -135,8 +136,10 @@ abstract class DBLockManager extends QuorumLockManager {
$this->getConnection( $lockSrv );
} catch ( DBError $e ) {
$this->cacheRecordFailure( $lockSrv );
+
return false; // failed to connect
}
+
return true;
}
@@ -175,6 +178,7 @@ abstract class DBLockManager extends QuorumLockManager {
if ( !$this->conns[$lockDb]->trxLevel() ) {
$this->conns[$lockDb]->begin( __METHOD__ ); // start transaction
}
+
return $this->conns[$lockDb];
}
@@ -186,7 +190,8 @@ abstract class DBLockManager extends QuorumLockManager {
* @return void
* @throws DBError
*/
- protected function initConnection( $lockDb, DatabaseBase $db ) {}
+ protected function initConnection( $lockDb, DatabaseBase $db ) {
+ }
/**
* Checks if the DB has not recently had connection/query errors.
@@ -374,7 +379,7 @@ class PostgreSqlLockManager extends DBLockManager {
$db = $this->getConnection( $lockSrv ); // checked in isServerUp()
$bigints = array_unique( array_map(
- function( $key ) {
+ function ( $key ) {
return wfBaseConvert( substr( $key, 0, 15 ), 16, 10 );
},
array_map( array( $this, 'sha1Base16Absolute' ), $paths )
diff --git a/includes/filebackend/lockmanager/FSLockManager.php b/includes/filebackend/lockmanager/FSLockManager.php
index eacba7042e11..ec9bca50655b 100644
--- a/includes/filebackend/lockmanager/FSLockManager.php
+++ b/includes/filebackend/lockmanager/FSLockManager.php
@@ -77,6 +77,7 @@ class FSLockManager extends LockManager {
} else {
// Abort and unlock everything
$status->merge( $this->doUnlock( $lockedPaths, $type ) );
+
return $status;
}
}
@@ -205,6 +206,7 @@ class FSLockManager extends LockManager {
$status->warning( 'lockmanager-fail-closelock', $path );
}
}
+
return $status;
}
@@ -221,6 +223,7 @@ class FSLockManager extends LockManager {
}
unset( $this->handles[$path] );
}
+
return $status;
}
diff --git a/includes/filebackend/lockmanager/LSLockManager.php b/includes/filebackend/lockmanager/LSLockManager.php
index 97de8dca6a39..80643c1a1ea8 100644
--- a/includes/filebackend/lockmanager/LSLockManager.php
+++ b/includes/filebackend/lockmanager/LSLockManager.php
@@ -179,6 +179,7 @@ class LSLockManager extends QuorumLockManager {
if ( $response === false ) {
return false;
}
+
return trim( $response );
}
@@ -203,6 +204,7 @@ class LSLockManager extends QuorumLockManager {
stream_set_timeout( $conn, $sec, $usec );
$this->conns[$lockSrv] = $conn;
}
+
return $this->conns[$lockSrv];
}
diff --git a/includes/filebackend/lockmanager/LockManager.php b/includes/filebackend/lockmanager/LockManager.php
index dad8a6246841..eca153bc0689 100644
--- a/includes/filebackend/lockmanager/LockManager.php
+++ b/includes/filebackend/lockmanager/LockManager.php
@@ -119,6 +119,7 @@ abstract class LockManager {
$elapsed = microtime( true ) - $start;
} while ( $elapsed < $timeout && $elapsed >= 0 );
wfProfileOut( __METHOD__ );
+
return $status;
}
@@ -145,6 +146,7 @@ abstract class LockManager {
$pathsByType = $this->normalizePathsByType( $pathsByType );
$status = $this->doUnlockByType( $pathsByType );
wfProfileOut( __METHOD__ );
+
return $status;
}
@@ -185,6 +187,7 @@ abstract class LockManager {
foreach ( $pathsByType as $type => $paths ) {
$res[$this->lockTypeMap[$type]] = array_unique( $paths );
}
+
return $res;
}
@@ -209,6 +212,7 @@ abstract class LockManager {
break;
}
}
+
return $status;
}
@@ -232,6 +236,7 @@ abstract class LockManager {
foreach ( $pathsByType as $type => $paths ) {
$status->merge( $this->doUnlock( $paths, $type ) );
}
+
return $status;
}
diff --git a/includes/filebackend/lockmanager/LockManagerGroup.php b/includes/filebackend/lockmanager/LockManagerGroup.php
index 9aff241528b9..451b79ebb993 100644
--- a/includes/filebackend/lockmanager/LockManagerGroup.php
+++ b/includes/filebackend/lockmanager/LockManagerGroup.php
@@ -54,6 +54,7 @@ class LockManagerGroup {
self::$instances[$domain] = new self( $domain );
self::$instances[$domain]->initFromGlobals();
}
+
return self::$instances[$domain];
}
@@ -121,6 +122,7 @@ class LockManagerGroup {
$config = $this->managers[$name]['config'];
$this->managers[$name]['instance'] = new $class( $config );
}
+
return $this->managers[$name]['instance'];
}
@@ -136,6 +138,7 @@ class LockManagerGroup {
throw new MWException( "No lock manager defined with the name `$name`." );
}
$class = $this->managers[$name]['class'];
+
return array( 'class' => $class ) + $this->managers[$name]['config'];
}
diff --git a/includes/filebackend/lockmanager/MemcLockManager.php b/includes/filebackend/lockmanager/MemcLockManager.php
index 5eab03eef0c9..8b8c20316f6e 100644
--- a/includes/filebackend/lockmanager/MemcLockManager.php
+++ b/includes/filebackend/lockmanager/MemcLockManager.php
@@ -136,6 +136,7 @@ class MemcLockManager extends QuorumLockManager {
foreach ( $paths as $path ) {
$status->fatal( 'lockmanager-fail-acquirelock', $path );
}
+
return $status;
}
@@ -208,6 +209,7 @@ class MemcLockManager extends QuorumLockManager {
foreach ( $paths as $path ) {
$status->fatal( 'lockmanager-fail-releaselock', $path );
}
+
return;
}
@@ -280,6 +282,7 @@ class MemcLockManager extends QuorumLockManager {
return null; // server appears to be down
}
}
+
return $memc;
}
@@ -307,6 +310,7 @@ class MemcLockManager extends QuorumLockManager {
return $a;
} else {
trigger_error( __METHOD__ . ": reset invalid lock array.", E_USER_WARNING );
+
return self::newLockArray();
}
}
diff --git a/includes/filebackend/lockmanager/QuorumLockManager.php b/includes/filebackend/lockmanager/QuorumLockManager.php
index 8356d32a6436..749e934766ec 100644
--- a/includes/filebackend/lockmanager/QuorumLockManager.php
+++ b/includes/filebackend/lockmanager/QuorumLockManager.php
@@ -65,6 +65,7 @@ abstract class QuorumLockManager extends LockManager {
$status->merge( $this->doLockingRequestBucket( $bucket, $pathsToLockByType ) );
if ( !$status->isOK() ) {
$status->merge( $this->doUnlockByType( $lockedPaths ) );
+
return $status;
}
// Record these locks as active
diff --git a/includes/filebackend/lockmanager/RedisLockManager.php b/includes/filebackend/lockmanager/RedisLockManager.php
index 43b0198a6885..3863610b83ca 100644
--- a/includes/filebackend/lockmanager/RedisLockManager.php
+++ b/includes/filebackend/lockmanager/RedisLockManager.php
@@ -120,6 +120,7 @@ class RedisLockManager extends QuorumLockManager {
foreach ( $paths as $path ) {
$status->fatal( 'lockmanager-fail-acquirelock', $path );
}
+
return $status;
}
@@ -204,6 +205,7 @@ LUA;
foreach ( $paths as $path ) {
$status->fatal( 'lockmanager-fail-releaselock', $path );
}
+
return $status;
}
diff --git a/includes/filebackend/lockmanager/ScopedLock.php b/includes/filebackend/lockmanager/ScopedLock.php
index 5faad4a64468..b35b934abe87 100644
--- a/includes/filebackend/lockmanager/ScopedLock.php
+++ b/includes/filebackend/lockmanager/ScopedLock.php
@@ -74,6 +74,7 @@ class ScopedLock {
if ( $lockStatus->isOK() ) {
return new self( $manager, $pathsByType, $status );
}
+
return null;
}