define and use closeAndRename() after last write of xml dump file; convert from popen...
authorAriel Glenn <ariel@users.mediawiki.org>
Sat, 27 Aug 2011 18:31:03 +0000 (18:31 +0000)
committerAriel Glenn <ariel@users.mediawiki.org>
Sat, 27 Aug 2011 18:31:03 +0000 (18:31 +0000)
includes/Export.php
maintenance/dumpTextPass.php

index c496a38..55faf97 100644 (file)
@@ -704,6 +704,10 @@ class DumpOutput {
                return;
        }
 
+       function closeAndRename( $newname ) {
+               return;
+       }
+
        function rename( $newname ) {
                return;
        }
@@ -752,6 +756,21 @@ class DumpFileOutput extends DumpOutput {
                }
        }
 
+       function closeAndRename( $newname ) {
+               if ( is_array($newname) ) {
+                       if (count($newname) > 1) {
+                               throw new MWException("Export closeRenameAndReopen: passed multiple argumnts for rename of single file\n");
+                       }
+                       else {
+                               $newname = $newname[0];
+                       }
+               }
+               if ( $newname ) {
+                       fclose( $this->handle );
+                       rename( $this->filename, $newname );
+               }
+       }
+
        function rename( $newname ) {
                if ( is_array($newname) ) {
                        if (count($newname) > 1) {
@@ -784,11 +803,21 @@ class DumpPipeOutput extends DumpFileOutput {
                if ( !is_null( $file ) ) {
                        $command .=  " > " . wfEscapeShellArg( $file );
                }
-               $this->handle = popen( $command, "w" );
+               
+               $this->startCommand($command);
                $this->command = $command;
                $this->filename = $file;
        }
 
+       function startCommand($command) {
+               $spec = array(
+                       0 => array( "pipe", "r" ),
+               );
+               $pipes = array();
+               $this->procOpenResource = proc_open( $command, $spec, $pipes );
+               $this->handle = $pipes[0];
+       }
+
        /**
         * Close the old file, move it to a specified name, 
         * and reopen new file with the old name. 
@@ -803,11 +832,29 @@ class DumpPipeOutput extends DumpFileOutput {
                        }
                }
                if ( $newname ) {
-                       pclose( $this->handle );
+                       fclose( $this->handle );
+                       proc_close($this->procOpenResource);
                        rename( $this->filename, $newname );
                        $command = $this->command;
                        $command .=  " > " . wfEscapeShellArg( $this->filename );
-                       $this->handle = popen( $command, "w" );
+                       $this->startCommand($command);
+               }
+       }
+
+       function closeAndRename( $newname ) {
+               if ( is_array($newname) ) {
+                       if (count($newname) > 1) {
+                               throw new MWException("Export closeRenameAndReopen: passed multiple argumnts for rename of single file\n");
+                       }
+                       else {
+                               $newname = $newname[0];
+                       }
+               }
+               if ( $newname ) {
+#                      pclose( $this->handle );
+                       fclose( $this->handle );
+                       proc_close($this->procOpenResource);
+                       rename( $this->filename, $newname );
                }
        }
 
@@ -872,11 +919,28 @@ class Dump7ZipOutput extends DumpPipeOutput {
                        }
                }
                if ( $newname ) {
-                       pclose( $this->handle );
+                       fclose( $this->handle );
+                       proc_close($this->procOpenResource);
                        rename( $this->filename, $newname );
                        $command = "7za a -bd -si " . wfEscapeShellArg( $file );
                        $command .= ' >' . wfGetNull() . ' 2>&1';
-                       $this->handle = popen( $command, "w" );
+                       $this->startCommand($command);
+               }
+       }
+
+       function closeAndRename( $newname ) {
+               if ( is_array($newname) ) {
+                       if (count($newname) > 1) {
+                               throw new MWException("Export closeRenameAndReopen: passed multiple argumnts for rename of single file\n");
+                       }
+                       else {
+                               $newname = $newname[0];
+                       }
+               }
+               if ( $newname ) {
+                       fclose( $this->handle );
+                       proc_close($this->procOpenResource);
+                       rename( $this->filename, $newname );
                }
        }
 
@@ -944,6 +1008,10 @@ class DumpFilter {
                $this->sink->closeRenameAndReopen( $newname );
        }
 
+       function closeAndRename( $newname ) {
+               $this->sink->closeAndRename( $newname );
+       }
+
        function rename( $newname ) {
                $this->sink->rename( $newname );
        }
@@ -1106,6 +1174,11 @@ class DumpMultiWriter {
                }
        }
 
+       function closeAndRename( $newname ) {
+               for( $i = 0; $i < $this->count; $i++ ) {
+                       $this->sinks[$i]->closeAndRename( $newnames[$i] );
+               }
+       }
        function rename( $newnames ) {
                for( $i = 0; $i < $this->count; $i++ ) {
                        $this->sinks[$i]->rename( $newnames[$i] );
index 5a4abfa..c891a02 100644 (file)
@@ -308,7 +308,7 @@ class TextPassDumper extends BackupDumper {
                                        $fileinfo = pathinfo($filenameList[$i]);
                                        $newFilenames[] = $fileinfo{'dirname'} . '/' . $checkpointNameFilledIn;
                                }
-                               $this->egress->rename( $newFilenames );
+                               $this->egress->closeAndRename( $newFilenames );
                        }
                }
                xml_parser_free( $parser );