r108791 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108790‎ | r108791 | r108792 >
Date:04:32, 13 January 2012
Author:aaron
Status:ok
Tags:
Comment:
* Distinguish "does not exist" from failure in FSFileBackend::doGetFileStat().
* Added clearstatcache() to doConcatenate() to make it safe for callers to stat the file.
* A few minor comment tweaks.
Modified paths:
  • /trunk/phase3/includes/filerepo/backend/FSFileBackend.php (modified) (history)
  • /trunk/phase3/includes/filerepo/backend/FileBackend.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/backend/FSFileBackend.php
@@ -405,17 +405,19 @@
406406 return false; // invalid storage path
407407 }
408408
409 - wfSuppressWarnings();
 409+ $this->trapWarnings();
410410 $stat = is_file( $source ) ? stat( $source ) : false; // regular files only
411 - wfRestoreWarnings();
 411+ $hadError = $this->untrapWarnings();
412412
413413 if ( $stat ) {
414414 return array(
415415 'mtime' => wfTimestamp( TS_MW, $stat['mtime'] ),
416416 'size' => $stat['size']
417417 );
 418+ } elseif ( !$hadError ) {
 419+ return false; // file does not exist
418420 } else {
419 - return false;
 421+ return null; // failure
420422 }
421423 }
422424
@@ -495,6 +497,31 @@
496498
497499 return $ok;
498500 }
 501+
 502+ /**
 503+ * Suppress E_WARNING errors and track whether any happen
 504+ *
 505+ * @return void
 506+ */
 507+ protected function trapWarnings() {
 508+ $this->hadWarningErrors[] = false; // push to stack
 509+ set_error_handler( array( $this, 'handleWarning' ), E_WARNING );
 510+ }
 511+
 512+ /**
 513+ * Unsuppress E_WARNING errors and return true if any happened
 514+ *
 515+ * @return bool
 516+ */
 517+ protected function untrapWarnings() {
 518+ restore_error_handler(); // restore previous handler
 519+ return array_pop( $this->hadWarningErrors ); // pop from stack
 520+ }
 521+
 522+ private function handleWarning() {
 523+ $this->hadWarningErrors[count( $this->hadWarningErrors ) - 1] = true;
 524+ return true; // suppress from PHP handler
 525+ }
499526 }
500527
501528 /**
Index: trunk/phase3/includes/filerepo/backend/FileBackend.php
@@ -305,9 +305,9 @@
306306 abstract protected function doPrepare( array $params );
307307
308308 /**
309 - * Take measures to block web access to a directory and
 309+ * Take measures to block web access to a storage directory and
310310 * the container it belongs to. FS backends might add .htaccess
311 - * files wheras backends like Swift this might restrict container
 311+ * files whereas backends like Swift this might restrict container
312312 * access to backend user that represents end-users in web request.
313313 * This is not guaranteed to actually do anything.
314314 *
@@ -774,6 +774,8 @@
775775 return $status;
776776 }
777777
 778+ clearstatcache(); // temp file changed
 779+
778780 return $status;
779781 }
780782

Status & tagging log