Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd behaviour on CentOS (and RHEL) #81

Closed
dinkel opened this issue Jun 4, 2014 · 4 comments
Closed

Odd behaviour on CentOS (and RHEL) #81

dinkel opened this issue Jun 4, 2014 · 4 comments

Comments

@dinkel
Copy link

dinkel commented Jun 4, 2014

I just had to find out, that CentOS (and obviously RHEL) have PHP installed without the 'posix' module. This leads to an odd behaviour in 'is_writable'. See the console capture that shows the problem:

$ cat composer.json 
{
    "require": {
        "mikey179/vfsStream": "*"
    }
}
$ php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing mikey179/vfsstream (v1.2.0)
    Downloading: 100%         

Writing lock file
Generating autoload files
$ cat posix_module_test.php 
<?php

require_once "vendor/autoload.php";

use org\bovigo\vfs\vfsStream;

vfsStream::setup("base", 0755);

$stat = stat(vfsStream::url("base"));

$expected_uid = trim(`id -u`);

$actual_uid = trim($stat["uid"]);

if ($expected_uid != $actual_uid)
{
    echo "Failed asserting that " . $actual_uid . " is " . $expected_uid . "\n";
}

if (!is_writable(vfsStream::url("base")))
{
    echo "This wrongly means that the directory is said to not be writable!\n";
}
$ php -m | grep posix
$ php posix_module_test.php 
Failed asserting that 0 is 500
This wrongly means that the directory is said to not be writable!
$ sudo yum install php-process
$ php -m | grep posix
posix
$ php posix_module_test.php 
$ 

The problem - as far as I understand it - lies in the fact, that the virtual 'base' driectory is created as root (0) because it get's the UID through vfsStream#getCurrentUser(). The PHP function 'is_writable' is using the correct current user, which is 500 in my case and therefore is not allowed to write to the virtual 'base'.

I cannot really say what my expectations are: Is it simply a 'Known issue' or is there a possibility in the code to overcome this odd behaviour?

@mikey179
Copy link
Member

mikey179 commented Jun 4, 2014

Currently, the implemention of vfsStream::getCurrentUser() returns the current user according to posix, but if posix is not available it simply returns 0. On Linux systems vfsStream should return the value of trim(id -u); instead. On Windows though I'm a unsure what to do - posix is not available anyway, and I guess trim(id -u); doesn't work on Windows. Unfortunately I don't have a Windows system available any more to test this.

@staabm
Copy link

staabm commented Jun 5, 2014

id -u is not available on windows, just tested on windows7x64, maybe @romainneutron knows what todo?

@dinkel
Copy link
Author

dinkel commented Jun 6, 2014

In my opinion a solution with (a backticked) "id -u" would be very hacky and ugly - I just used it in the example for documentation purposes. As far as I understand the function "id", it is not even sure, that all UNIX systems necessarily have it available. My Linux box (Xubuntu 13.10) and my OpenBSD box (5.5) both have it available, but I have no clue about AIX, HPUX, MacOS, Solaris, etc.

@mikey179
Copy link
Member

I decided to not look into any further possibilities. Instead, I added a note in the requirements that Posix must be enabled. As on Windows no Posix is available I can't add it to the requirements in the composer.json file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants