https://bugzilla.wikimedia.org/show_bug.cgi?id=20244

--- Comment #4 from Max Semenik <maxsem.w...@gmail.com> 2011-01-26 18:14:52 UTC 
---
As the matter of fact, we're already attempting to make the path absolute, but
since we call realpath() before attempting to create the directory, it may
fail. Here's my fix for it, I can't currently commit it myself.

Index: SqliteInstaller.php
===================================================================
--- SqliteInstaller.php    (revision 77580)
+++ SqliteInstaller.php    (working copy)
@@ -45,16 +45,30 @@
             $this->getTextBox( 'wgDBname', 'config-db-name', array(),
$this->parent->getHelpBox( 'config-sqlite-name-help' ) );
     }

+    /*
+     * Safe wrapper for PHP's realpath() that fails gracefully if it's unable
to canonicalize the path.
+     */
+    private static function realpath( $path ) {
+        $result = realpath( $path );
+        if ( !$result ) {
+            return $path;
+        }
+        return $result;
+    }
+
     public function submitConnectForm() {
         $this->setVarsFromRequest( array( 'wgSQLiteDataDir', 'wgDBname' ) );

-        $dir = realpath( $this->getVar( 'wgSQLiteDataDir' ) );
-        if ( !$dir ) {
-            // realpath() sometimes fails, especially on Windows
-            $dir = $this->getVar( 'wgSQLiteDataDir' );
+        # Try realpath() if the directory already exists
+        $dir = self::realpath( $this->getVar( 'wgSQLiteDataDir' ) );
+        $result = self::dataDirOKmaybeCreate( $dir, true /* create? */ );
+        if ( $result->isOK() )
+        {
+            # Try expanding again in case we've just created it
+            $dir = self::realpath( $dir );
+            $this->setVar( 'wgSQLiteDataDir', $dir );
         }
-        $this->setVar( 'wgSQLiteDataDir', $dir );
-        return self::dataDirOKmaybeCreate( $dir, true /* create? */ );
+        return $result;
     }

     private static function dataDirOKmaybeCreate( $dir, $create = false ) {

-- 
Configure bugmail: https://bugzilla.wikimedia.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
You are on the CC list for the bug.

_______________________________________________
Wikibugs-l mailing list
Wikibugs-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to