Page MenuHomePhabricator

SQLite installation via CLI fails to expand ~paths
Closed, DeclinedPublic

Description

Running a cli installation, I got the following error:

$ php maintenance/install.php --dbtype=sqlite --dbpath=~/work/code/mediawiki/data wiki admin
...
You can install MediaWiki.
Setting up database
Cannot create the data directory ~/work/code/mediawiki/data, because the parent
directory ~/work/code/mediawiki is not writable by the webserver.
The installer has determined the user your webserver is running as.
Make the data directory writable by it to continue.
On a Unix/Linux system do:

cd ~/work/code/mediawiki
mkdir data
chgrp mah data
chmod g+w data

I followed the above directions, but they didn't help. Thinking it was a permissions problem of some kind I just erased the data subdirectory, but that didn't work. Evidently it doesn't expand the ~ properly. When I wrote out "/home/mah", I got:

$ php maintenance/install.php --dbtype=sqlite --dbpath=/home/mah/work/code/mediawiki/data wiki admin
...
You can install MediaWiki.
Setting up database
Unable to write to the directory "/home/mah/work/code/mediawiki/data".
Change its permissions so that the webserver can write to it, and try again.

In this case it was unable to write because I had removed the directory. The previous message implied that it was going to create the directory, but evidently it lied.

When I created the directory and used the full path instead of ~, it worked.


Version: 1.18.x
Severity: normal

Details

Reference
bz28512

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 11:25 PM
bzimport set Reference to bz28512.
bzimport added a subscriber: Unknown Object (MLST).

~ expansion is done by the shell, not by mediawiki.

Whate shell are you using?

Seems that something like 'echo foo=~/foo' expands it, but echo --foo=~/foo does not.

Alternatively, use --dbpath=$HOME/work/code/mediawiki/data which is the POSIX way.

(In reply to comment #1)

Whate shell are you using?

Bash.

Seems that something like 'echo foo=~/foo' expands it, but echo --foo=~/foo
does not.

I tried realpath("~") but got nothing. I suggest that a warning is at least given if ~ is the first character of the path. Also, it should actually try to create the data subdir.

I didn't mention, using an space is another way to make it happen:
php maintenance/install.php --dbtype=sqlite --dbpath ~/data wiki admin

The way to add that feature would be:
if (substr($value, 0, 2) == '~/') { $value = getenv("HOME") . substr($value, 1); }

note that your suggestion ignores cases of tilde expansion like ~www/ which would expand to the www user's home directory. You would have to call, This looks more complex than I initially anticipated:

if ( substr( $value, 0, 1 ) == '~') {
  $home = getenv("HOME");
  if ( is_string($home) && $value == "~" ) {
    $value = "$home/";
  } else if ( is_string( $home ) && substr( $value, 0, 2 ) == '~/' ) {
    $value = $home . substr($value, 1);
  } else if ( substr( $value, 0, 1 ) == '~' &&
    strlen( $value ) > 2 &&
    function_exists( "posix_getpwnam" ) ) {
    $offset = strpos( $value, "/" );
    if($offset == false ) {
      $offset = strlen($value);
      $value = "$value/";
    }

    $pwent = posix_getpwnam( substr( $value, 1, $offset - 1 ) );
    if( isset( $pwent['dir'] ) ) {
      $value = $pwent['dir'] . substr( $value, $offset );
    }
  }
}
if ( substr( $value, 0, 1 ) == '~') {
  die( "Couldn't expand the tilde\n" );
}

sumanah wrote:

Decided today in IRC that this is low-priority.

For reference: From IRC discussion today:

Chad Horohoe: Rather than trying to jump through hoops to figure out where the path is, why not just error out when a ~ path is given and say "give a full path please"

Greg Sabino Mullane: That's some hacky code there. Why are we not just disallowing ~ ?

Chad: Exactly. It's easier just to say "don't do that" than anything else.

saper claimed this task.
saper subscribed.

This is a C-shell feature. if you insist, "~" is a valid part of the filename on POSIX system.