r97178 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97177‎ | r97178 | r97179 >
Date:17:18, 15 September 2011
Author:ariel
Status:resolved (Comments)
Tags:
Comment:
throw exception if rename of output file fails
Modified paths:
  • /trunk/phase3/includes/Export.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Export.php
@@ -759,8 +759,10 @@
760760 }
761761 if ( $newname ) {
762762 fclose( $this->handle );
763 - rename( $this->filename, $newname );
764 - if ( $open ) {
 763+ if (! rename( $this->filename, $newname ) ) {
 764+ throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" );
 765+ }
 766+ elseif ( $open ) {
765767 $this->handle = fopen( $this->filename, "wt" );
766768 }
767769 }
@@ -814,8 +816,10 @@
815817 if ( $newname ) {
816818 fclose( $this->handle );
817819 proc_close( $this->procOpenResource );
818 - rename( $this->filename, $newname );
819 - if ( $open ) {
 820+ if (! rename( $this->filename, $newname ) ) {
 821+ throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" );
 822+ }
 823+ elseif ( $open ) {
820824 $command = $this->command;
821825 $command .= " > " . wfEscapeShellArg( $this->filename );
822826 $this->startCommand( $command );
@@ -873,8 +877,10 @@
874878 if ( $newname ) {
875879 fclose( $this->handle );
876880 proc_close( $this->procOpenResource );
877 - rename( $this->filename, $newname );
878 - if ( $open ) {
 881+ if (! rename( $this->filename, $newname ) ) {
 882+ throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" );
 883+ }
 884+ elseif ( $open ) {
879885 $command = "7za a -bd -si " . wfEscapeShellArg( $file );
880886 // Suppress annoying useless crap from p7zip
881887 // Unfortunately this could suppress real error messages too

Follow-up revisions

RevisionCommit summaryAuthorDate
r101614clean up duplicated code, for fixme in r97178ariel11:08, 2 November 2011

Comments

#Comment by Hashar (talk | contribs)   16:12, 17 October 2011

Maybe you could use a wrapper function to avoid repeating the same code.

#Comment by ArielGlenn (talk | contribs)   11:16, 2 November 2011

reset to new after followup

Status & tagging log