r101614 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101613‎ | r101614 | r101615 >
Date:11:08, 2 November 2011
Author:ariel
Status:ok
Tags:
Comment:
clean up duplicated code, for fixme in r97178
Modified paths:
  • /trunk/phase3/includes/Export.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Export.php
@@ -763,7 +763,13 @@
764764 $this->closeAndRename( $newname, true );
765765 }
766766
767 - function closeAndRename( $newname, $open = false ) {
 767+ function renameOrException( $newname ) {
 768+ if (! rename( $this->filename, $newname ) ) {
 769+ throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" );
 770+ }
 771+ }
 772+
 773+ function checkRenameArgCount( $newname ) {
768774 if ( is_array( $newname ) ) {
769775 if ( count( $newname ) > 1 ) {
770776 throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" );
@@ -771,12 +777,15 @@
772778 $newname = $newname[0];
773779 }
774780 }
 781+ return $newname;
 782+ }
 783+
 784+ function closeAndRename( $newname, $open = false ) {
 785+ $newname = $this->checkRenameArgCount( $newname );
775786 if ( $newname ) {
776787 fclose( $this->handle );
777 - if (! rename( $this->filename, $newname ) ) {
778 - throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" );
779 - }
780 - elseif ( $open ) {
 788+ $this->renameOrException( $newname );
 789+ if ( $open ) {
781790 $this->handle = fopen( $this->filename, "wt" );
782791 }
783792 }
@@ -820,20 +829,12 @@
821830 }
822831
823832 function closeAndRename( $newname, $open = false ) {
824 - if ( is_array( $newname ) ) {
825 - if ( count( $newname ) > 1 ) {
826 - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" );
827 - } else {
828 - $newname = $newname[0];
829 - }
830 - }
 833+ $newname = $this->checkRenameArgCount( $newname );
831834 if ( $newname ) {
832835 fclose( $this->handle );
833836 proc_close( $this->procOpenResource );
834 - if (! rename( $this->filename, $newname ) ) {
835 - throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" );
836 - }
837 - elseif ( $open ) {
 837+ $this->renameOrException( $newname );
 838+ if ( $open ) {
838839 $command = $this->command;
839840 $command .= " > " . wfEscapeShellArg( $this->filename );
840841 $this->startCommand( $command );
@@ -889,20 +890,12 @@
890891 }
891892
892893 function closeAndRename( $newname, $open = false ) {
893 - if ( is_array( $newname ) ) {
894 - if ( count( $newname ) > 1 ) {
895 - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" );
896 - } else {
897 - $newname = $newname[0];
898 - }
899 - }
 894+ $newname = $this->checkRenameArgCount( $newname );
900895 if ( $newname ) {
901896 fclose( $this->handle );
902897 proc_close( $this->procOpenResource );
903 - if (! rename( $this->filename, $newname ) ) {
904 - throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" );
905 - }
906 - elseif ( $open ) {
 898+ $this->renameOrException( $newname );
 899+ if ( $open ) {
907900 $command = setup7zCommand( $file );
908901 $this->startCommand( $command );
909902 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r97178throw exception if rename of output file failsariel17:18, 15 September 2011

Status & tagging log