From 164ce2bc63533be463bb8d5d520760e84c03e743 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 13 Jan 2012 04:32:28 +0000 Subject: [PATCH] * 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. --- includes/filerepo/backend/FSFileBackend.php | 33 +++++++++++++++++++-- includes/filerepo/backend/FileBackend.php | 6 ++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/includes/filerepo/backend/FSFileBackend.php b/includes/filerepo/backend/FSFileBackend.php index 4654070e6f..fbf101757a 100644 --- a/includes/filerepo/backend/FSFileBackend.php +++ b/includes/filerepo/backend/FSFileBackend.php @@ -405,17 +405,19 @@ class FSFileBackend extends FileBackend { return false; // invalid storage path } - wfSuppressWarnings(); + $this->trapWarnings(); $stat = is_file( $source ) ? stat( $source ) : false; // regular files only - wfRestoreWarnings(); + $hadError = $this->untrapWarnings(); if ( $stat ) { return array( 'mtime' => wfTimestamp( TS_MW, $stat['mtime'] ), 'size' => $stat['size'] ); + } elseif ( !$hadError ) { + return false; // file does not exist } else { - return false; + return null; // failure } } @@ -495,6 +497,31 @@ class FSFileBackend extends FileBackend { return $ok; } + + /** + * Suppress E_WARNING errors and track whether any happen + * + * @return void + */ + protected function trapWarnings() { + $this->hadWarningErrors[] = false; // push to stack + set_error_handler( array( $this, 'handleWarning' ), E_WARNING ); + } + + /** + * Unsuppress E_WARNING errors and return true if any happened + * + * @return bool + */ + protected function untrapWarnings() { + restore_error_handler(); // restore previous handler + return array_pop( $this->hadWarningErrors ); // pop from stack + } + + private function handleWarning() { + $this->hadWarningErrors[count( $this->hadWarningErrors ) - 1] = true; + return true; // suppress from PHP handler + } } /** diff --git a/includes/filerepo/backend/FileBackend.php b/includes/filerepo/backend/FileBackend.php index 76025c8b75..7af34efb02 100644 --- a/includes/filerepo/backend/FileBackend.php +++ b/includes/filerepo/backend/FileBackend.php @@ -305,9 +305,9 @@ abstract class FileBackendBase { abstract protected function doPrepare( array $params ); /** - * Take measures to block web access to a directory and + * Take measures to block web access to a storage directory and * the container it belongs to. FS backends might add .htaccess - * files wheras backends like Swift this might restrict container + * files whereas backends like Swift this might restrict container * access to backend user that represents end-users in web request. * This is not guaranteed to actually do anything. * @@ -774,6 +774,8 @@ abstract class FileBackend extends FileBackendBase { return $status; } + clearstatcache(); // temp file changed + return $status; } -- 2.20.1