Index: trunk/phase3/includes/filerepo/backend/FSFileBackend.php |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | * Sharding can be accomplished by using FileRepo-style hash paths. |
18 | 18 | * |
19 | 19 | * Status messages should avoid mentioning the internal FS paths. |
20 | | - * Likewise, error suppression should be used to avoid path disclosure. |
| 20 | + * PHP warnings are assumed to be logged rather than output. |
21 | 21 | * |
22 | 22 | * @ingroup FileBackend |
23 | 23 | * @since 1.19 |
— | — | @@ -41,14 +41,13 @@ |
42 | 42 | parent::__construct( $config ); |
43 | 43 | |
44 | 44 | // Remove any possible trailing slash from directories |
45 | | - |
46 | 45 | if ( isset( $config['basePath'] ) ) { |
47 | 46 | $this->basePath = rtrim( $config['basePath'], '/' ); // remove trailing slash |
48 | 47 | } else { |
49 | 48 | $this->basePath = null; // none; containers must have explicit paths |
50 | 49 | } |
51 | 50 | |
52 | | - if( isset( $config['containerPaths'] ) ) { |
| 51 | + if ( isset( $config['containerPaths'] ) ) { |
53 | 52 | $this->containerPaths = (array)$config['containerPaths']; |
54 | 53 | foreach ( $this->containerPaths as &$path ) { |
55 | 54 | $path = rtrim( $path, '/' ); // remove trailing slash |
— | — | @@ -140,13 +139,11 @@ |
141 | 140 | } |
142 | 141 | $parentDir = dirname( $fsPath ); |
143 | 142 | |
144 | | - wfSuppressWarnings(); |
145 | 143 | if ( file_exists( $fsPath ) ) { |
146 | 144 | $ok = is_file( $fsPath ) && is_writable( $fsPath ); |
147 | 145 | } else { |
148 | 146 | $ok = is_dir( $parentDir ) && is_writable( $parentDir ); |
149 | 147 | } |
150 | | - wfRestoreWarnings(); |
151 | 148 | |
152 | 149 | return $ok; |
153 | 150 | } |
— | — | @@ -166,9 +163,7 @@ |
167 | 164 | |
168 | 165 | if ( file_exists( $dest ) ) { |
169 | 166 | if ( !empty( $params['overwrite'] ) ) { |
170 | | - wfSuppressWarnings(); |
171 | 167 | $ok = unlink( $dest ); |
172 | | - wfRestoreWarnings(); |
173 | 168 | if ( !$ok ) { |
174 | 169 | $status->fatal( 'backend-fail-delete', $params['dst'] ); |
175 | 170 | return $status; |
— | — | @@ -179,9 +174,7 @@ |
180 | 175 | } |
181 | 176 | } |
182 | 177 | |
183 | | - wfSuppressWarnings(); |
184 | 178 | $ok = copy( $params['src'], $dest ); |
185 | | - wfRestoreWarnings(); |
186 | 179 | if ( !$ok ) { |
187 | 180 | $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] ); |
188 | 181 | return $status; |
— | — | @@ -213,9 +206,7 @@ |
214 | 207 | |
215 | 208 | if ( file_exists( $dest ) ) { |
216 | 209 | if ( !empty( $params['overwrite'] ) ) { |
217 | | - wfSuppressWarnings(); |
218 | 210 | $ok = unlink( $dest ); |
219 | | - wfRestoreWarnings(); |
220 | 211 | if ( !$ok ) { |
221 | 212 | $status->fatal( 'backend-fail-delete', $params['dst'] ); |
222 | 213 | return $status; |
— | — | @@ -226,9 +217,7 @@ |
227 | 218 | } |
228 | 219 | } |
229 | 220 | |
230 | | - wfSuppressWarnings(); |
231 | 221 | $ok = copy( $source, $dest ); |
232 | | - wfRestoreWarnings(); |
233 | 222 | if ( !$ok ) { |
234 | 223 | $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] ); |
235 | 224 | return $status; |
— | — | @@ -262,9 +251,7 @@ |
263 | 252 | if ( !empty( $params['overwrite'] ) ) { |
264 | 253 | // Windows does not support moving over existing files |
265 | 254 | if ( wfIsWindows() ) { |
266 | | - wfSuppressWarnings(); |
267 | 255 | $ok = unlink( $dest ); |
268 | | - wfRestoreWarnings(); |
269 | 256 | if ( !$ok ) { |
270 | 257 | $status->fatal( 'backend-fail-delete', $params['dst'] ); |
271 | 258 | return $status; |
— | — | @@ -276,10 +263,8 @@ |
277 | 264 | } |
278 | 265 | } |
279 | 266 | |
280 | | - wfSuppressWarnings(); |
281 | 267 | $ok = rename( $source, $dest ); |
282 | 268 | clearstatcache(); // file no longer at source |
283 | | - wfRestoreWarnings(); |
284 | 269 | if ( !$ok ) { |
285 | 270 | $status->fatal( 'backend-fail-move', $params['src'], $params['dst'] ); |
286 | 271 | return $status; |
— | — | @@ -308,9 +293,7 @@ |
309 | 294 | return $status; // do nothing; either OK or bad status |
310 | 295 | } |
311 | 296 | |
312 | | - wfSuppressWarnings(); |
313 | 297 | $ok = unlink( $source ); |
314 | | - wfRestoreWarnings(); |
315 | 298 | if ( !$ok ) { |
316 | 299 | $status->fatal( 'backend-fail-delete', $params['src'] ); |
317 | 300 | return $status; |
— | — | @@ -334,9 +317,7 @@ |
335 | 318 | |
336 | 319 | if ( file_exists( $dest ) ) { |
337 | 320 | if ( !empty( $params['overwrite'] ) ) { |
338 | | - wfSuppressWarnings(); |
339 | 321 | $ok = unlink( $dest ); |
340 | | - wfRestoreWarnings(); |
341 | 322 | if ( !$ok ) { |
342 | 323 | $status->fatal( 'backend-fail-delete', $params['dst'] ); |
343 | 324 | return $status; |
— | — | @@ -347,9 +328,7 @@ |
348 | 329 | } |
349 | 330 | } |
350 | 331 | |
351 | | - wfSuppressWarnings(); |
352 | 332 | $bytes = file_put_contents( $dest, $params['content'] ); |
353 | | - wfRestoreWarnings(); |
354 | 333 | if ( $bytes === false ) { |
355 | 334 | $status->fatal( 'backend-fail-create', $params['dst'] ); |
356 | 335 | return $status; |
— | — | @@ -390,9 +369,7 @@ |
391 | 370 | $dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot; |
392 | 371 | // Seed new directories with a blank index.html, to prevent crawling... |
393 | 372 | if ( !empty( $params['noListing'] ) && !file_exists( "{$dir}/index.html" ) ) { |
394 | | - wfSuppressWarnings(); |
395 | 373 | $bytes = file_put_contents( "{$dir}/index.html", '' ); |
396 | | - wfRestoreWarnings(); |
397 | 374 | if ( !$bytes ) { |
398 | 375 | $status->fatal( 'backend-fail-create', $params['dir'] . '/index.html' ); |
399 | 376 | return $status; |
— | — | @@ -401,9 +378,7 @@ |
402 | 379 | // Add a .htaccess file to the root of the container... |
403 | 380 | if ( !empty( $params['noAccess'] ) ) { |
404 | 381 | if ( !file_exists( "{$contRoot}/.htaccess" ) ) { |
405 | | - wfSuppressWarnings(); |
406 | 382 | $bytes = file_put_contents( "{$contRoot}/.htaccess", "Deny from all\n" ); |
407 | | - wfRestoreWarnings(); |
408 | 383 | if ( !$bytes ) { |
409 | 384 | $storeDir = "mwstore://{$this->name}/{$shortCont}"; |
410 | 385 | $status->fatal( 'backend-fail-create', "{$storeDir}/.htaccess" ); |
— | — | @@ -441,7 +416,7 @@ |
442 | 417 | return false; // invalid storage path |
443 | 418 | } |
444 | 419 | |
445 | | - $this->trapWarnings(); |
| 420 | + $this->trapWarnings(); // don't trust 'false' if there were errors |
446 | 421 | $stat = is_file( $source ) ? stat( $source ) : false; // regular files only |
447 | 422 | $hadError = $this->untrapWarnings(); |
448 | 423 | |
— | — | @@ -472,16 +447,12 @@ |
473 | 448 | list( $b, $shortCont, $r ) = FileBackend::splitStoragePath( $params['dir'] ); |
474 | 449 | $contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid |
475 | 450 | $dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot; |
476 | | - wfSuppressWarnings(); |
477 | 451 | $exists = is_dir( $dir ); |
478 | | - wfRestoreWarnings(); |
479 | 452 | if ( !$exists ) { |
480 | 453 | wfDebug( __METHOD__ . "() given directory does not exist: '$dir'\n" ); |
481 | 454 | return array(); // nothing under this dir |
482 | 455 | } |
483 | | - wfSuppressWarnings(); |
484 | 456 | $readable = is_readable( $dir ); |
485 | | - wfRestoreWarnings(); |
486 | 457 | if ( !$readable ) { |
487 | 458 | wfDebug( __METHOD__ . "() given directory is unreadable: '$dir'\n" ); |
488 | 459 | return null; // bad permissions? |
— | — | @@ -520,9 +491,7 @@ |
521 | 492 | $tmpPath = $tmpFile->getPath(); |
522 | 493 | |
523 | 494 | // Copy the source file over the temp file |
524 | | - wfSuppressWarnings(); |
525 | 495 | $ok = copy( $source, $tmpPath ); |
526 | | - wfRestoreWarnings(); |
527 | 496 | if ( !$ok ) { |
528 | 497 | return null; |
529 | 498 | } |
— | — | @@ -547,17 +516,18 @@ |
548 | 517 | } |
549 | 518 | |
550 | 519 | /** |
551 | | - * Suppress E_WARNING errors and track whether any happen |
| 520 | + * Listen for E_WARNING errors and track whether any happen |
552 | 521 | * |
553 | | - * @return void |
| 522 | + * @return bool |
554 | 523 | */ |
555 | 524 | protected function trapWarnings() { |
556 | 525 | $this->hadWarningErrors[] = false; // push to stack |
557 | 526 | set_error_handler( array( $this, 'handleWarning' ), E_WARNING ); |
| 527 | + return false; // invoke normal PHP error handler |
558 | 528 | } |
559 | 529 | |
560 | 530 | /** |
561 | | - * Unsuppress E_WARNING errors and return true if any happened |
| 531 | + * Stop listening for E_WARNING errors and return true if any happened |
562 | 532 | * |
563 | 533 | * @return bool |
564 | 534 | */ |