* Distinguish "does not exist" from failure in FSFileBackend::doGetFileStat().
authorAaron Schulz <aaron@users.mediawiki.org>
Fri, 13 Jan 2012 04:32:28 +0000 (04:32 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Fri, 13 Jan 2012 04:32:28 +0000 (04:32 +0000)
* Added clearstatcache() to doConcatenate() to make it safe for callers to stat the file.
* A few minor comment tweaks.

includes/filerepo/backend/FSFileBackend.php
includes/filerepo/backend/FileBackend.php

index 4654070..fbf1017 100644 (file)
@@ -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
+       }
 }
 
 /**
index 76025c8..7af34ef 100644 (file)
@@ -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;
        }