https://www.mediawiki.org/wiki/Special:Code/MediaWiki/110084

Revision: 110084
Author:   aaron
Date:     2012-01-26 21:05:03 +0000 (Thu, 26 Jan 2012)
Log Message:
-----------
In FileBackendBase/FileBackend:
* Added normalizeStoragePath() function. Use it for normalizing paths in the 
stat cache. This way, if someone clears a non-normal form of path from the 
cache, it will actually work as expected.
* Removed 'abstract' flag from FileBackendBase::clearCache().
* Documentation tweaks.

Modified Paths:
--------------
    trunk/phase3/includes/filerepo/backend/FileBackend.php

Modified: trunk/phase3/includes/filerepo/backend/FileBackend.php
===================================================================
--- trunk/phase3/includes/filerepo/backend/FileBackend.php      2012-01-26 
21:04:32 UTC (rev 110083)
+++ trunk/phase3/includes/filerepo/backend/FileBackend.php      2012-01-26 
21:05:03 UTC (rev 110084)
@@ -87,6 +87,7 @@
        /**
         * This is the main entry point into the backend for write operations.
         * Callers supply an ordered list of operations to perform as a 
transaction.
+        * Files will be locked, the stat cache cleared, and then the 
operations attempted.
         * If any serious errors occur, all attempted operations will be rolled 
back.
         * 
         * $ops is an array of arrays. The outer array holds a list of 
operations.
@@ -154,9 +155,9 @@
         *                         This can increase performance for 
non-critical writes.
         *                         This has no effect unless the 'force' flag 
is set.
         * 
-        * Remarks:
+        * Remarks on locking:
         * File system paths given to operations should refer to files that are
-        * either locked or otherwise safe from modification from other 
processes.
+        * already locked or otherwise safe from modification from other 
processes.
         * Normally these files will be new temp files, which should be 
adequate.
         * 
         * Return value:
@@ -528,7 +529,7 @@
         * @param $paths Array Storage paths (optional)
         * @return void
         */
-       abstract public function clearCache( array $paths = null );
+       public function clearCache( array $paths = null ) {}
 
        /**
         * Lock the files at the given storage paths in the backend.
@@ -978,7 +979,10 @@
         */
        final public function getFileStat( array $params ) {
                wfProfileIn( __METHOD__ );
-               $path = $params['src'];
+               $path = self::normalizeStoragePath( $params['src'] );
+               if ( $path === null ) {
+                       return false; // invalid storage path
+               }
                $latest = !empty( $params['latest'] );
                if ( isset( $this->cache[$path]['stat'] ) ) {
                        // If we want the latest data, check that this cached
@@ -1255,7 +1259,10 @@
                        $this->cache = array();
                } else {
                        foreach ( $paths as $path ) {
-                               unset( $this->cache[$path] );
+                               $path = self::normalizeStoragePath( $path );
+                               if ( $path !== null ) {
+                                       unset( $this->cache[$path] );
+                               }
                        }
                }
                $this->doClearCache( $paths );
@@ -1310,8 +1317,28 @@
        }
 
        /**
-        * Split a storage path (e.g. 
"mwstore://backend/container/path/to/object")
-        * into a backend name, a container name, and a relative object path.
+        * Normalize a storage path by cleaning up directory separators.
+        * Returns null if the path is not of the format of a valid storage 
path.
+        * 
+        * @param $storagePath string
+        * @return string|null 
+        */
+       final public static function normalizeStoragePath( $storagePath ) {
+               list( $backend, $container, $relPath ) = 
self::splitStoragePath( $storagePath );
+               if ( $relPath !== null ) { // must be for this backend
+                       $relPath = self::normalizeContainerPath( $relPath );
+                       if ( $relPath !== null ) {
+                               return ( $relPath != '' )
+                                       ? 
"mwstore://{$backend}/{$container}/{$relPath}"
+                                       : "mwstore://{$backend}/{$container}";
+                       }
+               }
+               return null;
+       }
+
+       /**
+        * Split a storage path into a backend name, a container name, 
+        * and a relative file path. The relative path may be the empty string.
         *
         * @param $storagePath string
         * @return Array (backend, container, rel object) or (null, null, null)


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to