Umherirrender has submitted this change and it was merged.

Change subject: Make the autoload generator use forward slashes on all OSs
......................................................................


Make the autoload generator use forward slashes on all OSs

It was previously using the platform-specific directory separator, meaning
that we got backslashes on Windows and forward slashes on other OSs.

Bug: T77004
Change-Id: I5d502b54fddd55272e63d4a2a14b6d5de541263a
---
M includes/utils/AutoloadGenerator.php
1 file changed, 17 insertions(+), 4 deletions(-)

Approvals:
  Umherirrender: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/utils/AutoloadGenerator.php 
b/includes/utils/AutoloadGenerator.php
index 4e65e11..6149a23 100644
--- a/includes/utils/AutoloadGenerator.php
+++ b/includes/utils/AutoloadGenerator.php
@@ -50,11 +50,22 @@
                if ( !is_array( $flags ) ) {
                        $flags = array( $flags );
                }
-               $this->basepath = realpath( $basepath );
+               $this->basepath = self::platformAgnosticRealpath( $basepath );
                $this->collector = new ClassCollector;
                if ( in_array( 'local', $flags ) ) {
                        $this->variableName = 'wgAutoloadLocalClasses';
                }
+       }
+
+       /**
+        * Wrapper for realpath() that returns the same results (using forward
+        * slashes) on both Windows and *nix.
+        *
+        * @param string $path Parameter to realpath()
+        * @return string
+        */
+       protected static function platformAgnosticRealpath( $path ) {
+               return str_replace( '\\', '/', realpath( $path ) );
        }
 
        /**
@@ -65,7 +76,7 @@
         * @param string $inputPath Full path to the file containing the class
         */
        public function forceClassPath( $fqcn, $inputPath ) {
-               $path = realpath( $inputPath );
+               $path = self::platformAgnosticRealpath( $inputPath );
                if ( !$path ) {
                        throw new \Exception( "Invalid path: $inputPath" );
                }
@@ -78,9 +89,10 @@
        }
 
        /**
-        * @var string $inputPath Path to a php file to find classes within
+        * @param string $inputPath Path to a php file to find classes within
         */
        public function readFile( $inputPath ) {
+               $inputPath = self::platformAgnosticRealpath( $inputPath );
                $len = strlen( $this->basepath );
                if ( substr( $inputPath, 0, $len ) !== $this->basepath ) {
                        throw new \Exception( "Path is not within basepath: 
$inputPath" );
@@ -99,7 +111,8 @@
         *  for php files with either .php or .inc extensions
         */
        public function readDir( $dir ) {
-               $it = new RecursiveDirectoryIterator( realpath( $dir ) );
+               $it = new RecursiveDirectoryIterator(
+                       self::platformAgnosticRealpath( $dir ) );
                $it = new RecursiveIteratorIterator( $it );
 
                foreach ( $it as $path => $file ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5d502b54fddd55272e63d4a2a14b6d5de541263a
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: TTO <at.li...@live.com.au>
Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com>
Gerrit-Reviewer: Umherirrender <umherirrender_de...@web.de>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to