1

Is it possible to avoid this exception (maybe by excluding directories which can't be read by the PHP process because of a lack of permissions?). I can't find it in the docs.

RecursiveDirectoryIterator::__construct(/proc/tty/driver): 
failed to open dir: Permission denied

My code:

$filesystem = new Filesystem(new Local('/proc', LOCK_EX, Local::SKIP_LINKS));
$filesystem->listContents('.', true);
Michael Käfer
  • 1,597
  • 2
  • 19
  • 37
  • Instead of trying to work around this in PHP, I recommend figuring out why the permissions are incorrect. Also, Flysystem's goal is to provide a filesystem abstraction for storage. It seems you're trying to do something that will only ever be local. I recommend not using Flysystem for this, it's just not the tool for that job it seems. – Frank de Jonge Sep 11 '18 at 07:34
  • @FrankdeJonge I see, so your library is meant for the web (where we usually can control file permissions) and not for directories like /proc. For me that is the answer to my question. Thank you! – Michael Käfer Sep 15 '18 at 07:35
  • The /proc directories have tightened permissions which conflict with how PHP handles operations in some cases. Per linux distribution there's a group like wheel or admin or root which owns those directories and you can mostly only read them. However some read operations like listing contents require more than read permissions. This is the same for web and non-web, although in web situations you're more likely to have correct permissions. So the solution is to figure out how to get the right permissions for these operations. – Frank de Jonge Sep 15 '18 at 11:29
  • @FrankdeJonge Thank you very much for the clarification! – Michael Käfer Sep 18 '18 at 13:10

1 Answers1

1

See: https://github.com/thephpleague/flysystem/issues/831 its essentially the same issue.

To do the workaround you would need to extend the class and overwrite the method getRecursiveDirectoryIterator, as there is no way to change the RecursiveIteratorIterator modes.

Change the default mode to RecursiveIteratorIterator::CATCH_GET_CHILD which will not fail when it attempts to open.

For example:

<?php
class LocalSkipError extends Local {
    protected function getRecursiveDirectoryIterator($path, $mode = RecursiveIteratorIterator::CATCH_GET_CHILD)
    {
        return new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS),
            $mode
        );
    }
}

$filesystem = new Filesystem(new LocalSkipError('/proc', LOCK_EX, Local::SKIP_LINKS));
$filesystem->listContents('.', true);

But its not recommended:

Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106