From: Ariel Glenn Date: Sat, 27 Aug 2011 18:31:03 +0000 (+0000) Subject: define and use closeAndRename() after last write of xml dump file; convert from popen... X-Git-Tag: 1.31.0-rc.0~28044 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=0dcd589b6b85e968baaadf3dc791315b20fae2ce;p=lhc%2Fweb%2Fwiklou.git define and use closeAndRename() after last write of xml dump file; convert from popen (child inherits all open descriptors and there is no workaround) to proc_open (CLOEXEC set on all descriptors), needed so close and rename doesn't hang forever if a child (prefetcher) is forked --- diff --git a/includes/Export.php b/includes/Export.php index c496a38405..55faf975f7 100644 --- a/includes/Export.php +++ b/includes/Export.php @@ -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] ); diff --git a/maintenance/dumpTextPass.php b/maintenance/dumpTextPass.php index 5a4abfad70..c891a02f45 100644 --- a/maintenance/dumpTextPass.php +++ b/maintenance/dumpTextPass.php @@ -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 );