r107092 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107091‎ | r107092 | r107093 >
Date:19:10, 22 December 2011
Author:grafzahl
Status:ok
Tags:
Comment:
Create factory directory only if we need it
Modified paths:
  • /trunk/extensions/Score/Score.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Score/Score.body.php
@@ -113,6 +113,23 @@
114114 }
115115
116116 /**
 117+ * Creates the specified directory if it does not exist yet.
 118+ * Otherwise does nothing.
 119+ *
 120+ * @param $path path to directory to be created.
 121+ *
 122+ * @throws ScoreException if the directory does not exist and could not be created.
 123+ */
 124+ private static function createFactory( $path ) {
 125+ if ( !is_dir( $path ) ) {
 126+ $rc = wfMkdirParents( $path, 0700, __METHOD__ );
 127+ if ( !$rc ) {
 128+ throw new ScoreException( wfMessage( 'score-nofactory' ) );
 129+ }
 130+ }
 131+ }
 132+
 133+ /**
117134 * Renders the lilypond code in a <score>…</score> tag.
118135 *
119136 * @param $code
@@ -126,19 +143,11 @@
127144 global $wgTmpDirectory;
128145
129146 try {
130 - /* create working environment */
 147+ /* generate name for working environment */
131148 $factoryPrefix = 'MWLP.';
132149 $fuzz = md5( mt_rand() );
133150 $factoryDirectory = $wgTmpDirectory . "/$factoryPrefix$fuzz";
134 - $rc = wfMkdirParents( $factoryDirectory, 0700, __METHOD__ );
135 - if ( !$rc ) {
136 - throw new ScoreException( wfMessage( 'score-nofactory' ) );
137 - }
138 - } catch ( ScoreException $e ) {
139 - return $e;
140 - }
141151
142 - try {
143152 /* Midi rendering? */
144153 if ( array_key_exists( 'midi', $args ) ) {
145154 $renderMidi = $args['midi'];
@@ -164,6 +173,7 @@
165174 $lilypondCode = $code;
166175 $altText = false;
167176 }
 177+ self::createFactory( $factoryDirectory );
168178 $rc = file_put_contents( $lilypondFile, $lilypondCode );
169179 if ( $rc === false ) {
170180 throw new ScoreException( wfMessage( 'score-noinput', $lilypondFile ) );
@@ -177,6 +187,7 @@
178188 throw new ScoreException( wfMessage( 'score-invalidlang', $lang ) );
179189 }
180190
 191+ /* Run LilyPond */
181192 $html = self::runLilypond( $factoryDirectory, $renderMidi, $altText );
182193 } catch ( ScoreException $e ) {
183194 self::eraseFactory( $factoryDirectory );
@@ -242,6 +253,7 @@
243254 $lyFile = $factoryDirectory . '/file.ly';
244255
245256 /* Create ABC input file */
 257+ self::createFactory( $factoryDirectory );
246258 $rc = file_put_contents( $abcFile, ltrim( $code ) ); // abc2ly is picky about whitespace at the start of the file
247259 if ( $rc === false ) {
248260 throw new ScoreException( wfMessage( 'score-noabcinput', $abcFile ) );

Sign-offs

UserFlagDate
Nikerabbitinspected08:36, 23 December 2011

Status & tagging log