r107730 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107729‎ | r107730 | r107731 >
Date:18:18, 31 December 2011
Author:grafzahl
Status:deferred
Tags:score 
Comment:
Be more thorough with cleanup
Modified paths:
  • /trunk/extensions/Score/Score.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Score/Score.body.php
@@ -383,19 +383,11 @@
384384 $multiFormat = "$filePrefix-%d.png";
385385
386386 /* delete old files if necessary */
387 - $rc = true;
388 - if ( file_exists( $midi ) ) {
389 - $rc = $rc && unlink( $midi );
390 - }
391 - if ( file_exists( $image ) ) {
392 - $rc = $rc && unlink( $image );
393 - }
 387+ self::cleanupFile( $midi );
 388+ self::cleanupFile( $image );
394389 for ( $i = 1; file_exists( $f = sprintf( $multiFormat, $i ) ); ++$i ) {
395 - $rc = $rc && unlink( $f );
 390+ self::cleanupFile( $f );
396391 }
397 - if ( !$rc ) {
398 - throw new ScoreException( wfMessage( 'score-cleanerr' ) );
399 - }
400392
401393 /* Create the working environment */
402394 self::createFactory( $factoryDirectory );
@@ -543,6 +535,9 @@
544536 $midi = "$filePrefix.midi";
545537 $ogg = "$filePrefix.ogg";
546538
 539+ /* Delete old file if necessary */
 540+ self::cleanupFile( $ogg );
 541+
547542 /* Run timidity */
548543 if ( !is_executable( $wgScoreTimidity ) ) {
549544 throw new ScoreException( wfMessage( 'score-timiditynotexecutable', $wgScoreTimidity ) );
@@ -581,6 +576,10 @@
582577
583578 $ly = "$filePrefix.ly";
584579
 580+ /* Delete old file if necessary */
 581+ self::cleanupFile( $ly );
 582+
 583+ /* Generate LilyPond code by score language */
585584 switch ( $options['lang'] ) {
586585 case 'ABC':
587586 $lilypondCode = self::generateLilypondFromAbc( $code, $factoryDirectory );
@@ -591,6 +590,7 @@
592591 throw new MWException( 'Unknown score language in ' . __METHOD__ . ". This should not happen.\n" );
593592 }
594593
 594+ /* Create LilyPond file and return the code */
595595 $rc = file_put_contents( $ly, $lilypondCode );
596596 if ( $rc === false ) {
597597 self::debug( "Unable to write LilyPond code to $ly.\n" );
@@ -709,6 +709,23 @@
710710 }
711711
712712 /**
 713+ * Deletes a file if it exists.
 714+ *
 715+ * @param $path string path to the file to be deleted.
 716+ *
 717+ * @throws ScoreException if the file specified by $path exists but
 718+ * could not be deleted.
 719+ */
 720+ private static function cleanupFile( $path ) {
 721+ if ( file_exists( $path ) ) {
 722+ $rc = unlink( $path );
 723+ if ( !$rc ) {
 724+ throw new ScoreException( wfMessage( 'score-cleanerr' ) );
 725+ }
 726+ }
 727+ }
 728+
 729+ /**
713730 * Writes the specified message to the Score debug log.
714731 *
715732 * @param $msg string message to log.

Status & tagging log