Krinkle has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/276677

Change subject: wmfstatic: Remove redundant file_exists check
......................................................................

wmfstatic: Remove redundant file_exists check

realpath() already verifies that the path exists.

Move the stat() call to after the contentType check (which inspects the
string only, not the file). This saves an I/O call for unsupported paths.

Change-Id: I2df480010e3929ab6f9bd5a1cf053a01a9c2a760
---
M w/static.php
1 file changed, 8 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/mediawiki-config 
refs/changes/77/276677/1

diff --git a/w/static.php b/w/static.php
index 84fb20d..7b10eef 100644
--- a/w/static.php
+++ b/w/static.php
@@ -41,17 +41,18 @@
  * @param string $responseType Cache control for successful repsonse (one of 
'short' or 'long')
  */
 function wmfStaticStreamFile( $filePath, $responseType = 'nohash' ) {
+       $ctype = StreamFile::contentTypeFromPath( $filePath, /* safe: not for 
upload */ false );
+       if ( !$ctype || $ctype === 'unknown/unknown' ) {
+               // Directory, extension-less file or unknown extension
+               header( 'HTTP/1.1 400 Bad Request' );
+               wmfStaticShowError( 'Invalid path type' );
+               return;
+       }
+
        $stat = stat( $filePath );
        if ( !$stat ) {
                header( 'HTTP/1.1 404 Not Found' );
                wmfStaticShowError( 'Unknown file path' );
-               return;
-       }
-
-       $ctype = StreamFile::contentTypeFromPath( $filePath, /* safe: not for 
upload */ false );
-       if ( !$ctype || $ctype === 'unknown/unknown' ) {
-               header( 'HTTP/1.1 400 Bad Request' );
-               wmfStaticShowError( 'Invalid file type' );
                return;
        }
 
@@ -148,10 +149,6 @@
                        header( 'HTTP/1.1 400 Bad Request' );
                        wmfStaticShowError( 'Bad request' );
                        return;
-               }
-
-               if ( !file_exists( $filePath ) ) {
-                       continue;
                }
 
                if ( $urlHash ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/276677
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2df480010e3929ab6f9bd5a1cf053a01a9c2a760
Gerrit-PatchSet: 1
Gerrit-Project: operations/mediawiki-config
Gerrit-Branch: master
Gerrit-Owner: Krinkle <krinklem...@gmail.com>

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

Reply via email to