https://www.mediawiki.org/wiki/Special:Code/MediaWiki/106585
Revision: 106585 Author: aaron Date: 2011-12-18 19:23:21 +0000 (Sun, 18 Dec 2011) Log Message: ----------- * Added default copy+delete implementation for move() and removed canMove() * Simplified MoveFileOp to always use move() Modified Paths: -------------- branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php branches/FileBackend/phase3/includes/filerepo/backend/FileOp.php Modified: branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php =================================================================== --- branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php 2011-12-18 19:20:41 UTC (rev 106584) +++ branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php 2011-12-18 19:23:21 UTC (rev 106585) @@ -381,8 +381,7 @@ abstract public function copy( array $params ); /** - * Copy a file from one storage path to another in the backend. - * This can be left as a dummy function as long as hasMove() returns false. + * Move a file from one storage path to another in the backend. * Do not call this function from places outside FileBackend and FileOp. * $params include: * src : source storage path @@ -393,7 +392,14 @@ * @return Status */ public function move( array $params ) { - throw new MWException( "This function is not implemented." ); + // Copy source to dest + $status = $this->backend->copy( $params ); + if ( !$status->isOK() ) { + return $status; + } + // Delete source (only fails due to races or medium going down) + $this->backend->delete( array( 'src' => $this->params['src'] ) ); + return $status; } /** @@ -445,22 +451,6 @@ return Status::newGood(); } - /** - * Whether this backend can perform a move from one storage path to another. - * No backend hits are required. For example, moving objects across - * containers may not be supported. Do not call this function from places - * outside FileBackend and FileOp. - * $params include: - * src : source storage path - * dst : destination storage path - * - * @param $params Array - * @return bool - */ - public function canMove( array $params ) { - return false; // not implemented - } - public function getFileSha1Base36( array $params ) { $fsFile = $this->getLocalReference( array( 'src' => $params['src'] ) ); if ( !$fsFile ) { Modified: branches/FileBackend/phase3/includes/filerepo/backend/FileOp.php =================================================================== --- branches/FileBackend/phase3/includes/filerepo/backend/FileOp.php 2011-12-18 19:20:41 UTC (rev 106584) +++ branches/FileBackend/phase3/includes/filerepo/backend/FileOp.php 2011-12-18 19:23:21 UTC (rev 106585) @@ -47,7 +47,6 @@ } } $this->params = $params; - $this->initialize(); } /** @@ -265,11 +264,6 @@ } /** - * @return void - */ - protected function initialize() {} - - /** * @return Status */ protected function doPrecheck( array &$predicates ) { @@ -721,17 +715,10 @@ * overwriteSame : override any existing file at destination */ class MoveFileOp extends FileOp { - protected $usingMove = false; // using backend move() function? - protected function allowedParams() { return array( 'src', 'dst', 'overwriteDest', 'overwriteSame' ); } - protected function initialize() { - // Use faster, native, move() if applicable - $this->usingMove = $this->backend->canMove( $this->params ); - } - protected function doPrecheck( array &$predicates ) { $status = Status::newGood(); // Check if destination file exists @@ -760,23 +747,8 @@ } } if ( !$this->destSameAsSource ) { - // Native moves: move the file into the destination - if ( $this->usingMove ) { - $status->merge( $this->backend->move( $this->params ) ); - // Non-native moves: copy the file into the destination & delete source - } else { - // Copy source to dest - $status->merge( $this->backend->copy( $this->params ) ); - if ( !$status->isOK() ) { - return $status; - } - // Delete source - $params = array( 'src' => $this->params['src'] ); - $status->merge( $this->backend->delete( $params ) ); - if ( !$status->isOK() ) { - return $status; - } - } + // Move the file into the destination + $status->merge( $this->backend->move( $this->params ) ); } else { // Create a source backup copy as needed $status->merge( $this->backupSource() ); @@ -796,30 +768,14 @@ protected function doRevert() { $status = Status::newGood(); if ( !$this->destSameAsSource ) { - // Native moves: move the file back to the source - if ( $this->usingMove ) { - $params = array( - 'src' => $this->params['dst'], - 'dst' => $this->params['src'] - ); - $status->merge( $this->backend->move( $params ) ); - if ( !$status->isOK() ) { - return $status; // also can't restore any dest file - } - // Non-native moves: remove the file saved to the destination - } else { - // Copy destination back to source - $params = array( 'src' => $this->params['dst'], 'dst' => $this->params['src'] ); - $status = $this->backend->copy( $params ); - if ( !$status->isOK() ) { - return $status; // also can't restore any dest file - } - // Delete destination - $params = array( 'src' => $this->params['dst'] ); - $status = $this->backend->delete( $params ); - if ( !$status->isOK() ) { - return $status; // also can't restore any dest file - } + // Move the file back to the source + $params = array( + 'src' => $this->params['dst'], + 'dst' => $this->params['src'] + ); + $status->merge( $this->backend->move( $params ) ); + if ( !$status->isOK() ) { + return $status; // also can't restore any dest file } // Restore any file that was at the destination $status->merge( $this->restoreDest() ); _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs