r106585 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106584‎ | r106585 | r106586 >
Date:19:23, 18 December 2011
Author:aaron
Status:deferred
Tags:
Comment:
* 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 (modified) (history)
  • /branches/FileBackend/phase3/includes/filerepo/backend/FileOp.php (modified) (history)

Diff [purge]

Index: branches/FileBackend/phase3/includes/filerepo/backend/FileOp.php
@@ -47,7 +47,6 @@
4848 }
4949 }
5050 $this->params = $params;
51 - $this->initialize();
5251 }
5352
5453 /**
@@ -265,11 +264,6 @@
266265 }
267266
268267 /**
269 - * @return void
270 - */
271 - protected function initialize() {}
272 -
273 - /**
274268 * @return Status
275269 */
276270 protected function doPrecheck( array &$predicates ) {
@@ -721,17 +715,10 @@
722716 * overwriteSame : override any existing file at destination
723717 */
724718 class MoveFileOp extends FileOp {
725 - protected $usingMove = false; // using backend move() function?
726 -
727719 protected function allowedParams() {
728720 return array( 'src', 'dst', 'overwriteDest', 'overwriteSame' );
729721 }
730722
731 - protected function initialize() {
732 - // Use faster, native, move() if applicable
733 - $this->usingMove = $this->backend->canMove( $this->params );
734 - }
735 -
736723 protected function doPrecheck( array &$predicates ) {
737724 $status = Status::newGood();
738725 // Check if destination file exists
@@ -760,23 +747,8 @@
761748 }
762749 }
763750 if ( !$this->destSameAsSource ) {
764 - // Native moves: move the file into the destination
765 - if ( $this->usingMove ) {
766 - $status->merge( $this->backend->move( $this->params ) );
767 - // Non-native moves: copy the file into the destination & delete source
768 - } else {
769 - // Copy source to dest
770 - $status->merge( $this->backend->copy( $this->params ) );
771 - if ( !$status->isOK() ) {
772 - return $status;
773 - }
774 - // Delete source
775 - $params = array( 'src' => $this->params['src'] );
776 - $status->merge( $this->backend->delete( $params ) );
777 - if ( !$status->isOK() ) {
778 - return $status;
779 - }
780 - }
 751+ // Move the file into the destination
 752+ $status->merge( $this->backend->move( $this->params ) );
781753 } else {
782754 // Create a source backup copy as needed
783755 $status->merge( $this->backupSource() );
@@ -796,30 +768,14 @@
797769 protected function doRevert() {
798770 $status = Status::newGood();
799771 if ( !$this->destSameAsSource ) {
800 - // Native moves: move the file back to the source
801 - if ( $this->usingMove ) {
802 - $params = array(
803 - 'src' => $this->params['dst'],
804 - 'dst' => $this->params['src']
805 - );
806 - $status->merge( $this->backend->move( $params ) );
807 - if ( !$status->isOK() ) {
808 - return $status; // also can't restore any dest file
809 - }
810 - // Non-native moves: remove the file saved to the destination
811 - } else {
812 - // Copy destination back to source
813 - $params = array( 'src' => $this->params['dst'], 'dst' => $this->params['src'] );
814 - $status = $this->backend->copy( $params );
815 - if ( !$status->isOK() ) {
816 - return $status; // also can't restore any dest file
817 - }
818 - // Delete destination
819 - $params = array( 'src' => $this->params['dst'] );
820 - $status = $this->backend->delete( $params );
821 - if ( !$status->isOK() ) {
822 - return $status; // also can't restore any dest file
823 - }
 772+ // Move the file back to the source
 773+ $params = array(
 774+ 'src' => $this->params['dst'],
 775+ 'dst' => $this->params['src']
 776+ );
 777+ $status->merge( $this->backend->move( $params ) );
 778+ if ( !$status->isOK() ) {
 779+ return $status; // also can't restore any dest file
824780 }
825781 // Restore any file that was at the destination
826782 $status->merge( $this->restoreDest() );
Index: branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php
@@ -381,8 +381,7 @@
382382 abstract public function copy( array $params );
383383
384384 /**
385 - * Copy a file from one storage path to another in the backend.
386 - * This can be left as a dummy function as long as hasMove() returns false.
 385+ * Move a file from one storage path to another in the backend.
387386 * Do not call this function from places outside FileBackend and FileOp.
388387 * $params include:
389388 * src : source storage path
@@ -393,7 +392,14 @@
394393 * @return Status
395394 */
396395 public function move( array $params ) {
397 - throw new MWException( "This function is not implemented." );
 396+ // Copy source to dest
 397+ $status = $this->backend->copy( $params );
 398+ if ( !$status->isOK() ) {
 399+ return $status;
 400+ }
 401+ // Delete source (only fails due to races or medium going down)
 402+ $this->backend->delete( array( 'src' => $this->params['src'] ) );
 403+ return $status;
398404 }
399405
400406 /**
@@ -445,22 +451,6 @@
446452 return Status::newGood();
447453 }
448454
449 - /**
450 - * Whether this backend can perform a move from one storage path to another.
451 - * No backend hits are required. For example, moving objects across
452 - * containers may not be supported. Do not call this function from places
453 - * outside FileBackend and FileOp.
454 - * $params include:
455 - * src : source storage path
456 - * dst : destination storage path
457 - *
458 - * @param $params Array
459 - * @return bool
460 - */
461 - public function canMove( array $params ) {
462 - return false; // not implemented
463 - }
464 -
465455 public function getFileSha1Base36( array $params ) {
466456 $fsFile = $this->getLocalReference( array( 'src' => $params['src'] ) );
467457 if ( !$fsFile ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r106596* Removed canMove() from FSFileBackend, left from r106585....aaron20:19, 18 December 2011

Status & tagging log