Index: trunk/phase3/includes/Export.php |
— | — | @@ -709,17 +709,21 @@ |
710 | 710 | return; |
711 | 711 | } |
712 | 712 | |
713 | | - // TODO: document |
714 | | - function closeAndRename( $newname ) { |
| 713 | + /** |
| 714 | + * Close the old file, and move it to a specified name. |
| 715 | + * Use this for the last piece of a file written out |
| 716 | + * at specified checkpoints (e.g. every n hours). |
| 717 | + * @param $newname mixed File name. May be a string or an array with one element |
| 718 | + * @param $open bool If true, a new file with the old filename will be opened again for writing (default: false) |
| 719 | + */ |
| 720 | + function closeAndRename( $newname, $open = false ) { |
715 | 721 | return; |
716 | 722 | } |
717 | 723 | |
718 | | - // TODO: document |
719 | | - function rename( $newname ) { |
720 | | - return; |
721 | | - } |
722 | | - |
723 | | - // TODO: document |
| 724 | + /** |
| 725 | + * Returns the name of the file or files which are |
| 726 | + * being written to, if there are any. |
| 727 | + */ |
724 | 728 | function getFilename() { |
725 | 729 | return NULL; |
726 | 730 | } |
— | — | @@ -742,21 +746,10 @@ |
743 | 747 | } |
744 | 748 | |
745 | 749 | function closeRenameAndReopen( $newname ) { |
746 | | - if ( is_array( $newname ) ) { |
747 | | - if ( count( $newname ) > 1 ) { |
748 | | - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); |
749 | | - } else { |
750 | | - $newname = $newname[0]; |
751 | | - } |
752 | | - } |
753 | | - if ( $newname ) { |
754 | | - fclose( $this->handle ); |
755 | | - rename( $this->filename, $newname ); |
756 | | - $this->handle = fopen( $this->filename, "wt" ); |
757 | | - } |
| 750 | + $this->closeAndRename( $newname, true ); |
758 | 751 | } |
759 | 752 | |
760 | | - function closeAndRename( $newname ) { |
| 753 | + function closeAndRename( $newname, $open = false ) { |
761 | 754 | if ( is_array( $newname ) ) { |
762 | 755 | if ( count( $newname ) > 1 ) { |
763 | 756 | throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); |
— | — | @@ -767,20 +760,10 @@ |
768 | 761 | if ( $newname ) { |
769 | 762 | fclose( $this->handle ); |
770 | 763 | rename( $this->filename, $newname ); |
771 | | - } |
772 | | - } |
773 | | - |
774 | | - function rename( $newname ) { |
775 | | - if ( is_array( $newname ) ) { |
776 | | - if ( count( $newname ) > 1 ) { |
777 | | - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); |
778 | | - } else { |
779 | | - $newname = $newname[0]; |
| 764 | + if ( $open ) { |
| 765 | + $this->handle = fopen( $this->filename, "wt" ); |
780 | 766 | } |
781 | 767 | } |
782 | | - if ( $newname ) { |
783 | | - rename( $this->filename, $newname ); |
784 | | - } |
785 | 768 | } |
786 | 769 | |
787 | 770 | function getFilename() { |
— | — | @@ -816,29 +799,11 @@ |
817 | 800 | $this->handle = $pipes[0]; |
818 | 801 | } |
819 | 802 | |
820 | | - /** |
821 | | - * Close the old file, move it to a specified name, |
822 | | - * and reopen new file with the old name. |
823 | | - */ |
824 | 803 | function closeRenameAndReopen( $newname ) { |
825 | | - if ( is_array( $newname ) ) { |
826 | | - if ( count( $newname ) > 1 ) { |
827 | | - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); |
828 | | - } else { |
829 | | - $newname = $newname[0]; |
830 | | - } |
831 | | - } |
832 | | - if ( $newname ) { |
833 | | - fclose( $this->handle ); |
834 | | - proc_close( $this->procOpenResource ); |
835 | | - rename( $this->filename, $newname ); |
836 | | - $command = $this->command; |
837 | | - $command .= " > " . wfEscapeShellArg( $this->filename ); |
838 | | - $this->startCommand( $command ); |
839 | | - } |
| 804 | + $this->closeAndRename( $newname, true ); |
840 | 805 | } |
841 | 806 | |
842 | | - function closeAndRename( $newname ) { |
| 807 | + function closeAndRename( $newname, $open = false ) { |
843 | 808 | if ( is_array( $newname ) ) { |
844 | 809 | if ( count( $newname ) > 1 ) { |
845 | 810 | throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); |
— | — | @@ -847,25 +812,17 @@ |
848 | 813 | } |
849 | 814 | } |
850 | 815 | if ( $newname ) { |
851 | | -# pclose( $this->handle ); |
852 | 816 | fclose( $this->handle ); |
853 | 817 | proc_close( $this->procOpenResource ); |
854 | 818 | rename( $this->filename, $newname ); |
855 | | - } |
856 | | - } |
857 | | - |
858 | | - function rename( $newname ) { |
859 | | - if ( is_array( $newname ) ) { |
860 | | - if ( count( $newname ) > 1 ) { |
861 | | - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); |
862 | | - } else { |
863 | | - $newname = $newname[0]; |
| 819 | + if ( $open ) { |
| 820 | + $command = $this->command; |
| 821 | + $command .= " > " . wfEscapeShellArg( $this->filename ); |
| 822 | + $this->startCommand( $command ); |
864 | 823 | } |
865 | 824 | } |
866 | | - if ( $newname ) { |
867 | | - rename( $this->filename, $newname ); |
868 | | - } |
869 | 825 | } |
| 826 | + |
870 | 827 | } |
871 | 828 | |
872 | 829 | /** |
— | — | @@ -896,34 +853,16 @@ |
897 | 854 | protected $filename; |
898 | 855 | |
899 | 856 | function __construct( $file ) { |
900 | | - $command = "7za a -bd -si " . wfEscapeShellArg( $file ); |
901 | | - // Suppress annoying useless crap from p7zip |
902 | | - // Unfortunately this could suppress real error messages too |
903 | | - $command .= ' >' . wfGetNull() . ' 2>&1'; |
| 857 | + $command = setup7zCommand( $file ); |
904 | 858 | parent::__construct( $command ); |
905 | 859 | $this->filename = $file; |
906 | 860 | } |
907 | 861 | |
908 | 862 | function closeRenameAndReopen( $newname ) { |
909 | | - if ( is_array( $newname ) ) { |
910 | | - if ( count( $newname ) > 1 ) { |
911 | | - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); |
912 | | - } |
913 | | - else { |
914 | | - $newname = $newname[0]; |
915 | | - } |
916 | | - } |
917 | | - if ( $newname ) { |
918 | | - fclose( $this->handle ); |
919 | | - proc_close( $this->procOpenResource ); |
920 | | - rename( $this->filename, $newname ); |
921 | | - $command = "7za a -bd -si " . wfEscapeShellArg( $file ); |
922 | | - $command .= ' >' . wfGetNull() . ' 2>&1'; |
923 | | - $this->startCommand( $command ); |
924 | | - } |
| 863 | + $this->closeAndRename( $newname, true ); |
925 | 864 | } |
926 | 865 | |
927 | | - function closeAndRename( $newname ) { |
| 866 | + function closeAndRename( $newname, $open = false ) { |
928 | 867 | if ( is_array( $newname ) ) { |
929 | 868 | if ( count( $newname ) > 1 ) { |
930 | 869 | throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); |
— | — | @@ -935,21 +874,14 @@ |
936 | 875 | fclose( $this->handle ); |
937 | 876 | proc_close( $this->procOpenResource ); |
938 | 877 | rename( $this->filename, $newname ); |
939 | | - } |
940 | | - } |
941 | | - |
942 | | - function rename( $newname ) { |
943 | | - if ( is_array( $newname ) ) { |
944 | | - if ( count( $newname ) > 1 ) { |
945 | | - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); |
| 878 | + if ( $open ) { |
| 879 | + $command = "7za a -bd -si " . wfEscapeShellArg( $file ); |
| 880 | + // Suppress annoying useless crap from p7zip |
| 881 | + // Unfortunately this could suppress real error messages too |
| 882 | + $command .= ' >' . wfGetNull() . ' 2>&1'; |
| 883 | + $this->startCommand( $command ); |
946 | 884 | } |
947 | | - else { |
948 | | - $newname = $newname[0]; |
949 | | - } |
950 | 885 | } |
951 | | - if ( $newname ) { |
952 | | - rename( $this->filename, $newname ); |
953 | | - } |
954 | 886 | } |
955 | 887 | } |
956 | 888 | |
— | — | @@ -1002,14 +934,10 @@ |
1003 | 935 | $this->sink->closeRenameAndReopen( $newname ); |
1004 | 936 | } |
1005 | 937 | |
1006 | | - function closeAndRename( $newname ) { |
1007 | | - $this->sink->closeAndRename( $newname ); |
| 938 | + function closeAndRename( $newname, $open = false ) { |
| 939 | + $this->sink->closeAndRename( $newname, $open ); |
1008 | 940 | } |
1009 | 941 | |
1010 | | - function rename( $newname ) { |
1011 | | - $this->sink->rename( $newname ); |
1012 | | - } |
1013 | | - |
1014 | 942 | function getFilename() { |
1015 | 943 | return $this->sink->getFilename(); |
1016 | 944 | } |
— | — | @@ -1163,21 +1091,14 @@ |
1164 | 1092 | } |
1165 | 1093 | |
1166 | 1094 | function closeRenameAndReopen( $newnames ) { |
1167 | | - for ( $i = 0; $i < $this->count; $i++ ) { |
1168 | | - $this->sinks[$i]->closeRenameAndReopen( $newnames[$i] ); |
1169 | | - } |
| 1095 | + $this->closeAndRename( $newnames, true ); |
1170 | 1096 | } |
1171 | 1097 | |
1172 | | - function closeAndRename( $newname ) { |
| 1098 | + function closeAndRename( $newnames, $open = false ) { |
1173 | 1099 | for ( $i = 0; $i < $this->count; $i++ ) { |
1174 | | - $this->sinks[$i]->closeAndRename( $newnames[$i] ); |
| 1100 | + $this->sinks[$i]->closeAndRename( $newnames[$i], $open ); |
1175 | 1101 | } |
1176 | 1102 | } |
1177 | | - function rename( $newnames ) { |
1178 | | - for ( $i = 0; $i < $this->count; $i++ ) { |
1179 | | - $this->sinks[$i]->rename( $newnames[$i] ); |
1180 | | - } |
1181 | | - } |
1182 | 1103 | |
1183 | 1104 | function getFilename() { |
1184 | 1105 | $filenames = array(); |