registration: Avoid redundant LBYL check in ExtensionRegistry::queue()
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 31 Aug 2019 21:08:35 +0000 (22:08 +0100)
committerKrinkle <krinklemail@gmail.com>
Sun, 1 Sep 2019 18:28:41 +0000 (18:28 +0000)
Avoids extra I/O, and with that the race condition it holds.

Bug: T187154
Change-Id: I46ded196835bcd677fe41da4890fc7998a0b4d17

includes/registration/ExtensionRegistry.php
tests/phpunit/includes/registration/ExtensionRegistryTest.php

index 3e65f6c..5663487 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 use Composer\Semver\Semver;
+use Wikimedia\AtEase\AtEase;
 use Wikimedia\ScopedCallback;
 use MediaWiki\Shell\Shell;
 use MediaWiki\ShellDisabledError;
@@ -126,15 +127,13 @@ class ExtensionRegistry {
 
                $mtime = $wgExtensionInfoMTime;
                if ( $mtime === false ) {
-                       if ( file_exists( $path ) ) {
-                               $mtime = filemtime( $path );
-                       } else {
-                               throw new Exception( "$path does not exist!" );
-                       }
+                       AtEase::suppressWarnings();
+                       $mtime = filemtime( $path );
+                       AtEase::restoreWarnings();
                        // @codeCoverageIgnoreStart
                        if ( $mtime === false ) {
                                $err = error_get_last();
-                               throw new Exception( "Couldn't stat $path: {$err['message']}" );
+                               throw new Exception( "Unable to open file $path: {$err['message']}" );
                                // @codeCoverageIgnoreEnd
                        }
                }
index 5de1b0c..106cca3 100644 (file)
@@ -19,7 +19,7 @@ class ExtensionRegistryTest extends MediaWikiTestCase {
                $path = __DIR__ . '/doesnotexist.json';
                $this->setExpectedException(
                        Exception::class,
-                       "$path does not exist!"
+                       "file $path"
                );
                $registry->queue( $path );
        }