Index: branches/FileBackend/phase3/includes/filerepo/backend/FileOp.php |
— | — | @@ -47,7 +47,6 @@ |
48 | 48 | } |
49 | 49 | } |
50 | 50 | $this->params = $params; |
51 | | - $this->initialize(); |
52 | 51 | } |
53 | 52 | |
54 | 53 | /** |
— | — | @@ -265,11 +264,6 @@ |
266 | 265 | } |
267 | 266 | |
268 | 267 | /** |
269 | | - * @return void |
270 | | - */ |
271 | | - protected function initialize() {} |
272 | | - |
273 | | - /** |
274 | 268 | * @return Status |
275 | 269 | */ |
276 | 270 | protected function doPrecheck( array &$predicates ) { |
— | — | @@ -721,17 +715,10 @@ |
722 | 716 | * overwriteSame : override any existing file at destination |
723 | 717 | */ |
724 | 718 | class MoveFileOp extends FileOp { |
725 | | - protected $usingMove = false; // using backend move() function? |
726 | | - |
727 | 719 | protected function allowedParams() { |
728 | 720 | return array( 'src', 'dst', 'overwriteDest', 'overwriteSame' ); |
729 | 721 | } |
730 | 722 | |
731 | | - protected function initialize() { |
732 | | - // Use faster, native, move() if applicable |
733 | | - $this->usingMove = $this->backend->canMove( $this->params ); |
734 | | - } |
735 | | - |
736 | 723 | protected function doPrecheck( array &$predicates ) { |
737 | 724 | $status = Status::newGood(); |
738 | 725 | // Check if destination file exists |
— | — | @@ -760,23 +747,8 @@ |
761 | 748 | } |
762 | 749 | } |
763 | 750 | 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 ) ); |
781 | 753 | } else { |
782 | 754 | // Create a source backup copy as needed |
783 | 755 | $status->merge( $this->backupSource() ); |
— | — | @@ -796,30 +768,14 @@ |
797 | 769 | protected function doRevert() { |
798 | 770 | $status = Status::newGood(); |
799 | 771 | 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 |
824 | 780 | } |
825 | 781 | // Restore any file that was at the destination |
826 | 782 | $status->merge( $this->restoreDest() ); |
Index: branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php |
— | — | @@ -381,8 +381,7 @@ |
382 | 382 | abstract public function copy( array $params ); |
383 | 383 | |
384 | 384 | /** |
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. |
387 | 386 | * Do not call this function from places outside FileBackend and FileOp. |
388 | 387 | * $params include: |
389 | 388 | * src : source storage path |
— | — | @@ -393,7 +392,14 @@ |
394 | 393 | * @return Status |
395 | 394 | */ |
396 | 395 | 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; |
398 | 404 | } |
399 | 405 | |
400 | 406 | /** |
— | — | @@ -445,22 +451,6 @@ |
446 | 452 | return Status::newGood(); |
447 | 453 | } |
448 | 454 | |
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 | | - |
465 | 455 | public function getFileSha1Base36( array $params ) { |
466 | 456 | $fsFile = $this->getLocalReference( array( 'src' => $params['src'] ) ); |
467 | 457 | if ( !$fsFile ) { |