From aed738967f0df7f5721bb0e1553b9be17a7f3d93 Mon Sep 17 00:00:00 2001 From: Ariel Glenn Date: Wed, 7 Sep 2011 20:21:52 +0000 Subject: [PATCH] get rid of duplication, remove unused function rename(), add documentation as per comments on r95260 --- includes/Export.php | 153 +++++++++++--------------------------------- 1 file changed, 37 insertions(+), 116 deletions(-) diff --git a/includes/Export.php b/includes/Export.php index 14d7690d7f..e6058b54b4 100644 --- a/includes/Export.php +++ b/includes/Export.php @@ -709,17 +709,21 @@ class DumpOutput { return; } - // TODO: document - function closeAndRename( $newname ) { - return; - } - - // TODO: document - function rename( $newname ) { + /** + * Close the old file, and move it to a specified name. + * Use this for the last piece of a file written out + * at specified checkpoints (e.g. every n hours). + * @param $newname mixed File name. May be a string or an array with one element + * @param $open bool If true, a new file with the old filename will be opened again for writing (default: false) + */ + function closeAndRename( $newname, $open = false ) { return; } - // TODO: document + /** + * Returns the name of the file or files which are + * being written to, if there are any. + */ function getFilename() { return NULL; } @@ -742,21 +746,10 @@ class DumpFileOutput extends DumpOutput { } function closeRenameAndReopen( $newname ) { - if ( is_array( $newname ) ) { - if ( count( $newname ) > 1 ) { - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); - } else { - $newname = $newname[0]; - } - } - if ( $newname ) { - fclose( $this->handle ); - rename( $this->filename, $newname ); - $this->handle = fopen( $this->filename, "wt" ); - } + $this->closeAndRename( $newname, true ); } - function closeAndRename( $newname ) { + function closeAndRename( $newname, $open = false ) { if ( is_array( $newname ) ) { if ( count( $newname ) > 1 ) { throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); @@ -767,20 +760,10 @@ class DumpFileOutput extends DumpOutput { if ( $newname ) { fclose( $this->handle ); rename( $this->filename, $newname ); - } - } - - function rename( $newname ) { - if ( is_array( $newname ) ) { - if ( count( $newname ) > 1 ) { - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); - } else { - $newname = $newname[0]; + if ( $open ) { + $this->handle = fopen( $this->filename, "wt" ); } } - if ( $newname ) { - rename( $this->filename, $newname ); - } } function getFilename() { @@ -816,29 +799,11 @@ class DumpPipeOutput extends DumpFileOutput { $this->handle = $pipes[0]; } - /** - * Close the old file, move it to a specified name, - * and reopen new file with the old name. - */ function closeRenameAndReopen( $newname ) { - if ( is_array( $newname ) ) { - if ( count( $newname ) > 1 ) { - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); - } else { - $newname = $newname[0]; - } - } - if ( $newname ) { - fclose( $this->handle ); - proc_close( $this->procOpenResource ); - rename( $this->filename, $newname ); - $command = $this->command; - $command .= " > " . wfEscapeShellArg( $this->filename ); - $this->startCommand( $command ); - } + $this->closeAndRename( $newname, true ); } - function closeAndRename( $newname ) { + function closeAndRename( $newname, $open = false ) { if ( is_array( $newname ) ) { if ( count( $newname ) > 1 ) { throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); @@ -847,25 +812,17 @@ class DumpPipeOutput extends DumpFileOutput { } } if ( $newname ) { -# pclose( $this->handle ); fclose( $this->handle ); proc_close( $this->procOpenResource ); rename( $this->filename, $newname ); - } - } - - function rename( $newname ) { - if ( is_array( $newname ) ) { - if ( count( $newname ) > 1 ) { - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); - } else { - $newname = $newname[0]; + if ( $open ) { + $command = $this->command; + $command .= " > " . wfEscapeShellArg( $this->filename ); + $this->startCommand( $command ); } } - if ( $newname ) { - rename( $this->filename, $newname ); - } } + } /** @@ -896,34 +853,16 @@ class Dump7ZipOutput extends DumpPipeOutput { protected $filename; function __construct( $file ) { - $command = "7za a -bd -si " . wfEscapeShellArg( $file ); - // Suppress annoying useless crap from p7zip - // Unfortunately this could suppress real error messages too - $command .= ' >' . wfGetNull() . ' 2>&1'; + $command = setup7zCommand( $file ); parent::__construct( $command ); $this->filename = $file; } function closeRenameAndReopen( $newname ) { - if ( is_array( $newname ) ) { - if ( count( $newname ) > 1 ) { - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); - } - else { - $newname = $newname[0]; - } - } - if ( $newname ) { - fclose( $this->handle ); - proc_close( $this->procOpenResource ); - rename( $this->filename, $newname ); - $command = "7za a -bd -si " . wfEscapeShellArg( $file ); - $command .= ' >' . wfGetNull() . ' 2>&1'; - $this->startCommand( $command ); - } + $this->closeAndRename( $newname, true ); } - function closeAndRename( $newname ) { + function closeAndRename( $newname, $open = false ) { if ( is_array( $newname ) ) { if ( count( $newname ) > 1 ) { throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); @@ -935,21 +874,14 @@ class Dump7ZipOutput extends DumpPipeOutput { fclose( $this->handle ); proc_close( $this->procOpenResource ); rename( $this->filename, $newname ); - } - } - - function rename( $newname ) { - if ( is_array( $newname ) ) { - if ( count( $newname ) > 1 ) { - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); - } - else { - $newname = $newname[0]; + if ( $open ) { + $command = "7za a -bd -si " . wfEscapeShellArg( $file ); + // Suppress annoying useless crap from p7zip + // Unfortunately this could suppress real error messages too + $command .= ' >' . wfGetNull() . ' 2>&1'; + $this->startCommand( $command ); } } - if ( $newname ) { - rename( $this->filename, $newname ); - } } } @@ -1002,12 +934,8 @@ class DumpFilter { $this->sink->closeRenameAndReopen( $newname ); } - function closeAndRename( $newname ) { - $this->sink->closeAndRename( $newname ); - } - - function rename( $newname ) { - $this->sink->rename( $newname ); + function closeAndRename( $newname, $open = false ) { + $this->sink->closeAndRename( $newname, $open ); } function getFilename() { @@ -1163,19 +1091,12 @@ class DumpMultiWriter { } function closeRenameAndReopen( $newnames ) { - for ( $i = 0; $i < $this->count; $i++ ) { - $this->sinks[$i]->closeRenameAndReopen( $newnames[$i] ); - } + $this->closeAndRename( $newnames, true ); } - function closeAndRename( $newname ) { - for ( $i = 0; $i < $this->count; $i++ ) { - $this->sinks[$i]->closeAndRename( $newnames[$i] ); - } - } - function rename( $newnames ) { + function closeAndRename( $newnames, $open = false ) { for ( $i = 0; $i < $this->count; $i++ ) { - $this->sinks[$i]->rename( $newnames[$i] ); + $this->sinks[$i]->closeAndRename( $newnames[$i], $open ); } } -- 2.20.1