Index: trunk/phase3/includes/Export.php |
— | — | @@ -763,7 +763,13 @@ |
764 | 764 | $this->closeAndRename( $newname, true ); |
765 | 765 | } |
766 | 766 | |
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 ) { |
768 | 774 | if ( is_array( $newname ) ) { |
769 | 775 | if ( count( $newname ) > 1 ) { |
770 | 776 | throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); |
— | — | @@ -771,12 +777,15 @@ |
772 | 778 | $newname = $newname[0]; |
773 | 779 | } |
774 | 780 | } |
| 781 | + return $newname; |
| 782 | + } |
| 783 | + |
| 784 | + function closeAndRename( $newname, $open = false ) { |
| 785 | + $newname = $this->checkRenameArgCount( $newname ); |
775 | 786 | if ( $newname ) { |
776 | 787 | 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 ) { |
781 | 790 | $this->handle = fopen( $this->filename, "wt" ); |
782 | 791 | } |
783 | 792 | } |
— | — | @@ -820,20 +829,12 @@ |
821 | 830 | } |
822 | 831 | |
823 | 832 | 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 ); |
831 | 834 | if ( $newname ) { |
832 | 835 | fclose( $this->handle ); |
833 | 836 | 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 ) { |
838 | 839 | $command = $this->command; |
839 | 840 | $command .= " > " . wfEscapeShellArg( $this->filename ); |
840 | 841 | $this->startCommand( $command ); |
— | — | @@ -889,20 +890,12 @@ |
890 | 891 | } |
891 | 892 | |
892 | 893 | 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 ); |
900 | 895 | if ( $newname ) { |
901 | 896 | fclose( $this->handle ); |
902 | 897 | 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 ) { |
907 | 900 | $command = setup7zCommand( $file ); |
908 | 901 | $this->startCommand( $command ); |
909 | 902 | } |