* Having directories with thousands of files will diminish performance.
* Sharding can be accomplished by using FileRepo-style hash paths.
*
- * Status messages should avoid mentioning the internal FS paths.
+ * StatusValue messages should avoid mentioning the internal FS paths.
* PHP warnings are assumed to be logged rather than output.
*
* @ingroup FileBackend
protected $basePath;
/** @var array Map of container names to root paths for custom container paths */
- protected $containerPaths = array();
+ protected $containerPaths = [];
/** @var int File permission mode */
protected $fileMode;
protected $currentUser;
/** @var array */
- protected $hadWarningErrors = array();
+ protected $hadWarningErrors = [];
/**
* @see FileBackendStore::__construct()
$this->fileMode = isset( $config['fileMode'] ) ? $config['fileMode'] : 0644;
if ( isset( $config['fileOwner'] ) && function_exists( 'posix_getuid' ) ) {
$this->fileOwner = $config['fileOwner'];
- $info = posix_getpwuid( posix_getuid() );
- $this->currentUser = $info['name']; // cache this, assuming it doesn't change
+ // cache this, assuming it doesn't change
+ $this->currentUser = posix_getpwuid( posix_getuid() )['name'];
}
}
}
protected function doCreateInternal( array $params ) {
- $status = Status::newGood();
+ $status = $this->newStatus();
$dest = $this->resolveToFSPath( $params['dst'] );
if ( $dest === null ) {
return $status;
}
- $cmd = implode( ' ', array(
+ $cmd = implode( ' ', [
wfIsWindows() ? 'COPY /B /Y' : 'cp', // (binary, overwrite)
wfEscapeShellArg( $this->cleanPathSlashes( $tempFile->getPath() ) ),
wfEscapeShellArg( $this->cleanPathSlashes( $dest ) )
- ) );
- $handler = function ( $errors, Status $status, array $params, $cmd ) {
+ ] );
+ $handler = function ( $errors, StatusValue $status, array $params, $cmd ) {
if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
$status->fatal( 'backend-fail-create', $params['dst'] );
trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
}
protected function doStoreInternal( array $params ) {
- $status = Status::newGood();
+ $status = $this->newStatus();
$dest = $this->resolveToFSPath( $params['dst'] );
if ( $dest === null ) {
}
if ( !empty( $params['async'] ) ) { // deferred
- $cmd = implode( ' ', array(
+ $cmd = implode( ' ', [
wfIsWindows() ? 'COPY /B /Y' : 'cp', // (binary, overwrite)
wfEscapeShellArg( $this->cleanPathSlashes( $params['src'] ) ),
wfEscapeShellArg( $this->cleanPathSlashes( $dest ) )
- ) );
- $handler = function ( $errors, Status $status, array $params, $cmd ) {
+ ] );
+ $handler = function ( $errors, StatusValue $status, array $params, $cmd ) {
if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
$status->fatal( 'backend-fail-store', $params['src'], $params['dst'] );
trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
}
protected function doCopyInternal( array $params ) {
- $status = Status::newGood();
+ $status = $this->newStatus();
$source = $this->resolveToFSPath( $params['src'] );
if ( $source === null ) {
}
if ( !empty( $params['async'] ) ) { // deferred
- $cmd = implode( ' ', array(
+ $cmd = implode( ' ', [
wfIsWindows() ? 'COPY /B /Y' : 'cp', // (binary, overwrite)
wfEscapeShellArg( $this->cleanPathSlashes( $source ) ),
wfEscapeShellArg( $this->cleanPathSlashes( $dest ) )
- ) );
- $handler = function ( $errors, Status $status, array $params, $cmd ) {
+ ] );
+ $handler = function ( $errors, StatusValue $status, array $params, $cmd ) {
if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
$status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
}
protected function doMoveInternal( array $params ) {
- $status = Status::newGood();
+ $status = $this->newStatus();
$source = $this->resolveToFSPath( $params['src'] );
if ( $source === null ) {
}
if ( !empty( $params['async'] ) ) { // deferred
- $cmd = implode( ' ', array(
+ $cmd = implode( ' ', [
wfIsWindows() ? 'MOVE /Y' : 'mv', // (overwrite)
wfEscapeShellArg( $this->cleanPathSlashes( $source ) ),
wfEscapeShellArg( $this->cleanPathSlashes( $dest ) )
- ) );
- $handler = function ( $errors, Status $status, array $params, $cmd ) {
+ ] );
+ $handler = function ( $errors, StatusValue $status, array $params, $cmd ) {
if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
$status->fatal( 'backend-fail-move', $params['src'], $params['dst'] );
trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
}
protected function doDeleteInternal( array $params ) {
- $status = Status::newGood();
+ $status = $this->newStatus();
$source = $this->resolveToFSPath( $params['src'] );
if ( $source === null ) {
}
if ( !empty( $params['async'] ) ) { // deferred
- $cmd = implode( ' ', array(
+ $cmd = implode( ' ', [
wfIsWindows() ? 'DEL' : 'unlink',
wfEscapeShellArg( $this->cleanPathSlashes( $source ) )
- ) );
- $handler = function ( $errors, Status $status, array $params, $cmd ) {
+ ] );
+ $handler = function ( $errors, StatusValue $status, array $params, $cmd ) {
if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
$status->fatal( 'backend-fail-delete', $params['src'] );
trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
* @param string $fullCont
* @param string $dirRel
* @param array $params
- * @return Status
+ * @return StatusValue
*/
protected function doPrepareInternal( $fullCont, $dirRel, array $params ) {
- $status = Status::newGood();
+ $status = $this->newStatus();
list( , $shortCont, ) = FileBackend::splitStoragePath( $params['dir'] );
$contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
$dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
}
protected function doSecureInternal( $fullCont, $dirRel, array $params ) {
- $status = Status::newGood();
+ $status = $this->newStatus();
list( , $shortCont, ) = FileBackend::splitStoragePath( $params['dir'] );
$contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
$dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
}
protected function doPublishInternal( $fullCont, $dirRel, array $params ) {
- $status = Status::newGood();
+ $status = $this->newStatus();
list( , $shortCont, ) = FileBackend::splitStoragePath( $params['dir'] );
$contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
$dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
}
protected function doCleanInternal( $fullCont, $dirRel, array $params ) {
- $status = Status::newGood();
+ $status = $this->newStatus();
list( , $shortCont, ) = FileBackend::splitStoragePath( $params['dir'] );
$contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
$dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
$hadError = $this->untrapWarnings();
if ( $stat ) {
- return array(
+ return [
'mtime' => wfTimestamp( TS_MW, $stat['mtime'] ),
'size' => $stat['size']
- );
+ ];
} elseif ( !$hadError ) {
return false; // file does not exist
} else {
if ( !$exists ) {
wfDebug( __METHOD__ . "() given directory does not exist: '$dir'\n" );
- return array(); // nothing under this dir
+ return []; // nothing under this dir
} elseif ( !is_readable( $dir ) ) {
wfDebug( __METHOD__ . "() given directory is unreadable: '$dir'\n" );
if ( !$exists ) {
wfDebug( __METHOD__ . "() given directory does not exist: '$dir'\n" );
- return array(); // nothing under this dir
+ return []; // nothing under this dir
} elseif ( !is_readable( $dir ) ) {
wfDebug( __METHOD__ . "() given directory is unreadable: '$dir'\n" );
}
protected function doGetLocalReferenceMulti( array $params ) {
- $fsFiles = array(); // (path => FSFile)
+ $fsFiles = []; // (path => FSFile)
foreach ( $params['srcs'] as $src ) {
$source = $this->resolveToFSPath( $src );
}
protected function doGetLocalCopyMulti( array $params ) {
- $tmpFiles = array(); // (path => TempFSFile)
+ $tmpFiles = []; // (path => TempFSFile)
foreach ( $params['srcs'] as $src ) {
$source = $this->resolveToFSPath( $src );
/**
* @param FSFileOpHandle[] $fileOpHandles
*
- * @return Status[]
+ * @return StatusValue[]
*/
protected function doExecuteOpHandlesInternal( array $fileOpHandles ) {
- $statuses = array();
+ $statuses = [];
- $pipes = array();
+ $pipes = [];
foreach ( $fileOpHandles as $index => $fileOpHandle ) {
$pipes[$index] = popen( "{$fileOpHandle->cmd} 2>&1", 'r' );
}
- $errs = array();
+ $errs = [];
foreach ( $pipes as $index => $pipe ) {
// Result will be empty on success in *NIX. On Windows,
// it may be something like " 1 file(s) [copied|moved].".
}
foreach ( $fileOpHandles as $index => $fileOpHandle ) {
- $status = Status::newGood();
+ $status = $this->newStatus();
$function = $fileOpHandle->call;
$function( $errs[$index], $status, $fileOpHandle->params, $fileOpHandle->cmd );
$statuses[$index] = $status;
*/
protected function trapWarnings() {
$this->hadWarningErrors[] = false; // push to stack
- set_error_handler( array( $this, 'handleWarning' ), E_WARNING );
+ set_error_handler( [ $this, 'handleWarning' ], E_WARNING );
}
/**
protected $pos = 0;
/** @var array */
- protected $params = array();
+ protected $params = [];
/**
* @param string $dir File system directory