[FileBackend] A few code cleanups and some error message improvements.

Change-Id: I75f066104b98638ca956042c4e877c0f6327509c
This commit is contained in:
Aaron 2012-05-17 11:28:05 -07:00
parent 4024de4bd8
commit 159cc27fde
6 changed files with 22 additions and 14 deletions

View file

@ -286,8 +286,7 @@ abstract class FileBackend {
* @return Status * @return Status
*/ */
final public function create( array $params, array $opts = array() ) { final public function create( array $params, array $opts = array() ) {
$params['op'] = 'create'; return $this->doOperation( array( 'op' => 'create' ) + $params, $opts );
return $this->doOperation( $params, $opts );
} }
/** /**
@ -301,8 +300,7 @@ abstract class FileBackend {
* @return Status * @return Status
*/ */
final public function store( array $params, array $opts = array() ) { final public function store( array $params, array $opts = array() ) {
$params['op'] = 'store'; return $this->doOperation( array( 'op' => 'store' ) + $params, $opts );
return $this->doOperation( $params, $opts );
} }
/** /**
@ -316,8 +314,7 @@ abstract class FileBackend {
* @return Status * @return Status
*/ */
final public function copy( array $params, array $opts = array() ) { final public function copy( array $params, array $opts = array() ) {
$params['op'] = 'copy'; return $this->doOperation( array( 'op' => 'copy' ) + $params, $opts );
return $this->doOperation( $params, $opts );
} }
/** /**
@ -331,8 +328,7 @@ abstract class FileBackend {
* @return Status * @return Status
*/ */
final public function move( array $params, array $opts = array() ) { final public function move( array $params, array $opts = array() ) {
$params['op'] = 'move'; return $this->doOperation( array( 'op' => 'move' ) + $params, $opts );
return $this->doOperation( $params, $opts );
} }
/** /**
@ -346,8 +342,7 @@ abstract class FileBackend {
* @return Status * @return Status
*/ */
final public function delete( array $params, array $opts = array() ) { final public function delete( array $params, array $opts = array() ) {
$params['op'] = 'delete'; return $this->doOperation( array( 'op' => 'delete' ) + $params, $opts );
return $this->doOperation( $params, $opts );
} }
/** /**

View file

@ -137,7 +137,8 @@ abstract class FileBackendStore extends FileBackend {
wfProfileIn( __METHOD__ ); wfProfileIn( __METHOD__ );
wfProfileIn( __METHOD__ . '-' . $this->name ); wfProfileIn( __METHOD__ . '-' . $this->name );
if ( filesize( $params['src'] ) > $this->maxFileSizeInternal() ) { if ( filesize( $params['src'] ) > $this->maxFileSizeInternal() ) {
$status = Status::newFatal( 'backend-fail-store', $params['dst'] ); $status = Status::newFatal( 'backend-fail-maxsize',
$params['dst'], $this->maxFileSizeInternal() );
} else { } else {
$status = $this->doStoreInternal( $params ); $status = $this->doStoreInternal( $params );
$this->clearCache( array( $params['dst'] ) ); $this->clearCache( array( $params['dst'] ) );

View file

@ -450,10 +450,13 @@ class StoreFileOp extends FileOp {
return $status; return $status;
// Check if the source file is too big // Check if the source file is too big
} elseif ( filesize( $this->params['src'] ) > $this->backend->maxFileSizeInternal() ) { } 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'] ); $status->fatal( 'backend-fail-store', $this->params['src'], $this->params['dst'] );
return $status; return $status;
// Check if a file can be placed at the destination // Check if a file can be placed at the destination
} elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) { } 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'] ); $status->fatal( 'backend-fail-store', $this->params['src'], $this->params['dst'] );
return $status; return $status;
} }
@ -507,10 +510,13 @@ class CreateFileOp extends FileOp {
$status = Status::newGood(); $status = Status::newGood();
// Check if the source data is too big // Check if the source data is too big
if ( strlen( $this->getParam( 'content' ) ) > $this->backend->maxFileSizeInternal() ) { if ( strlen( $this->getParam( 'content' ) ) > $this->backend->maxFileSizeInternal() ) {
$status->fatal( 'backend-fail-maxsize',
$this->params['dst'], $this->backend->maxFileSizeInternal() );
$status->fatal( 'backend-fail-create', $this->params['dst'] ); $status->fatal( 'backend-fail-create', $this->params['dst'] );
return $status; return $status;
// Check if a file can be placed at the destination // Check if a file can be placed at the destination
} elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) { } elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
$status->fatal( 'backend-fail-usable', $this->params['dst'] );
$status->fatal( 'backend-fail-create', $this->params['dst'] ); $status->fatal( 'backend-fail-create', $this->params['dst'] );
return $status; return $status;
} }
@ -562,6 +568,7 @@ class CopyFileOp extends FileOp {
return $status; return $status;
// Check if a file can be placed at the destination // Check if a file can be placed at the destination
} elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) { } 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'] ); $status->fatal( 'backend-fail-copy', $this->params['src'], $this->params['dst'] );
return $status; return $status;
} }
@ -616,6 +623,7 @@ class MoveFileOp extends FileOp {
return $status; return $status;
// Check if a file can be placed at the destination // Check if a file can be placed at the destination
} elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) { } 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'] ); $status->fatal( 'backend-fail-move', $this->params['src'], $this->params['dst'] );
return $status; return $status;
} }

View file

@ -2283,8 +2283,9 @@ If the problem persists, contact an [[Special:ListUsers/sysop|administrator]].',
'backend-fail-writetemp' => 'Could not write to temporary file.', 'backend-fail-writetemp' => 'Could not write to temporary file.',
'backend-fail-closetemp' => 'Could not close temporary file.', 'backend-fail-closetemp' => 'Could not close temporary file.',
'backend-fail-read' => 'Could not read file $1.', 'backend-fail-read' => 'Could not read file $1.',
'backend-fail-create' => 'Could not create file $1.', 'backend-fail-create' => 'Could not write file $1.',
'backend-fail-maxsize' => 'Could not create file $1 because it is larger than {{PLURAL:$2|one byte|$2 bytes}}.', 'backend-fail-maxsize' => 'Could not write file $1 because it is larger than {{PLURAL:$2|one byte|$2 bytes}}.',
'backend-fail-usable' => 'Could not write file $1 due to insufficient permissions or missing directories/containers.',
'backend-fail-readonly' => 'The storage backend "$1" is currently read-only. The reason given is: "\'\'$2\'\'"', 'backend-fail-readonly' => 'The storage backend "$1" is currently read-only. The reason given is: "\'\'$2\'\'"',
'backend-fail-synced' => 'The file "$1" is in an inconsistent state within the internal storage backends', 'backend-fail-synced' => 'The file "$1" is in an inconsistent state within the internal storage backends',
'backend-fail-connect' => 'Could not connect to storage backend "$1".', 'backend-fail-connect' => 'Could not connect to storage backend "$1".',

View file

@ -1966,6 +1966,8 @@ Extensions making use of it:
Parameters: Parameters:
* $1 is the number of operations attempted at once in this case. * $1 is the number of operations attempted at once in this case.
* $2 is the maximum number of operations that can be attempted at once.', * $2 is the maximum number of operations that can be attempted at once.',
'backend-fail-usable' => 'Parameters:
* $1 is a file path',
# File journal errors # File journal errors
'filejournal-fail-dbconnect' => 'Parameters: 'filejournal-fail-dbconnect' => 'Parameters:

View file

@ -1388,7 +1388,8 @@ $wgMessageStructure = array(
'backend-fail-connect', 'backend-fail-connect',
'backend-fail-internal', 'backend-fail-internal',
'backend-fail-contenttype', 'backend-fail-contenttype',
'backend-fail-batchsize' 'backend-fail-batchsize',
'backend-fail-usable'
), ),
'filejournal-errors' => array( 'filejournal-errors' => array(