flysystem-stream-wrapper icon indicating copy to clipboard operation
flysystem-stream-wrapper copied to clipboard

Calls to `uri_stat()` triggers a notice

Open sjadema opened this issue 6 years ago • 15 comments

When checking for directories with is_dir() and the directory exists, the following notice is thrown:

PHP Notice: Undefined offset: 0 in <SOME_PATH>/vendor/twistor/flysystem-stream-wrapper/src/Flysystem/Plugin/Stat.php on line 157

The following code should trigger the error:

<?php

use League\Flysystem\Filesystem;
use League\Flysystem\Memory\MemoryAdapter;
use Twistor\FlysystemStreamWrapper;

require_once 'vendor/autoload.php';

$filesystem = new Filesystem(new MemoryAdapter());
FlysystemStreamWrapper::register('test', $filesystem);

$directory = 'test:///test';
var_dump(is_dir($directory)); // Works as expected, no notice

mkdir($directory);
var_dump(is_dir($directory)); // Works as expected, but a notice is thrown

sjadema avatar Feb 26 '19 18:02 sjadema

This happens because $metadata['visibility'] = false. It tries to use that false as an index for $this->permissions and the false is casted to 0. The indexes in $this->permissions['dir'] are private & public hence the 0 isn't found.

sjadema avatar Feb 26 '19 23:02 sjadema

After doing some research, the error originates in het MemoryAdapter. When creating a new directory, the visibility isn't stored properly. I still think you should validate the metadata properties though.

sjadema avatar Feb 27 '19 00:02 sjadema

replace https://github.com/twistor/flysystem-stream-wrapper/blob/master/src/Flysystem/Plugin/Stat.php#L157 with

$ret['mode'] += empty($this->permissions[$metadata['type']][$metadata['visibility']]) ? $metadata['visibility'] : $this->permissions[$metadata['type']][$metadata['visibility']];

kor3k avatar Aug 26 '19 01:08 kor3k

A recent change in league/flysystem (1.0.55) is causing more problems with this: https://github.com/thephpleague/flysystem/commit/b0f7bee046dec58814f7f0fbe025c4ff4eb3fdc5 Error "Undefined index: 0666" is triggered in the mergeMeta function when calling $metadata = $this->filesystem->getMetadata($path); from Stat:getWithMetdata when working with the Local Adapter.

ronaldvdlp avatar Aug 29 '19 09:08 ronaldvdlp

the $metadata['visibility'] is supposed to be either a "named permission" string like public, or an octal pemission mode.

this should fix it for the moment: https://github.com/twistor/flysystem-stream-wrapper/pull/15/files

but it looks it will be changed again: https://github.com/thephpleague/flysystem/issues/1051

kor3k avatar Aug 29 '19 13:08 kor3k

the $metadata['visibility'] is supposed to be either a "named permission" string like public, or an octal pemission mode.

this should fix it for the moment: https://github.com/twistor/flysystem-stream-wrapper/pull/15/files

but it looks it will be changed again: thephpleague/flysystem#1051

tested and works 👍

oofz avatar Mar 15 '20 23:03 oofz

This is affecting usage on PHP 7.4.

This repo hasn't been updated in quite a while, is it no longer being maintained?

hexus avatar Jul 28 '20 13:07 hexus

@twistor, any chance we could get #15, #18 and #19 reviewed or merged? It appears that #15 and #19 address this particular error in different ways, and #18 is just about PHP 7.4 support in Travis.

hexus avatar Oct 19 '20 09:10 hexus

@hexus mine #15 was just a quick fix, but #19 looks more sophisticated, so i'd prefer this one. well, @twistor ain't responding for over a year 🤷‍♂️ so perhaps i'll make a fork and merge #18 and #19 in there.

kor3k avatar Oct 19 '20 20:10 kor3k

ok so here it is, tagged to v1.0.10: https://github.com/kor3k/flysystem-stream-wrapper

overriding packagist repo source in composer:

    "repositories": [
        {
            "type": "vcs",
            "url": "[email protected]:kor3k/flysystem-stream-wrapper.git"
        }
    ]

kor3k avatar Oct 19 '20 21:10 kor3k

Hi @kor3k I just stumbled upon your fork and really like that you made sure to have a version of this with the available bug fixes merged. I want to refer to your version in my composer requirements. As only root composer files can override repositories I basically can't reference it. Would you mind submitting your version to packagist with your prefix so one can easily pull in your version as dependency?

I am a bit sad that @twistor neglects this. Solutions are available and there seems to be activity by @twistor on GitHub. If this is not updated anymore please mark it as archived so we can be sure that someone else needs to step in.

JoshuaBehrens avatar Nov 05 '22 15:11 JoshuaBehrens

@JoshuaBehrens hello and thank you.

yes i'll take a look on adding it to packagist.

but, this is for flysystem v1, which is obsolete now. (imho that's why twistor is neglecting it). there is actively maintained version of stream wrapper for flysystem v2|v3. i recommend you to upgrade it in your projects if possible, like

"league/flysystem": "^3.0",
"m2mtech/flysystem-stream-wrapper": "^1.3",

kor3k avatar Nov 08 '22 02:11 kor3k

you're welcome @kor3k and thank you very much

I know I use the other wrapper already. In our library we use stream wrappers as abstraction layer. But at one point the library is used within shopware 6 and up to this point they depend on v1:

https://github.com/shopware/platform/blob/6.4.16.0/composer.json#L83-L85

        "league/flysystem": "~1.1.4",
        "league/flysystem-aws-s3-v3": "~1.0.29",
        "league/flysystem-memory": "~1.0.2",

JoshuaBehrens avatar Nov 08 '22 09:11 JoshuaBehrens

it is here: https://packagist.org/packages/kor3k/flysystem-stream-wrapper and tagged to v1.0.11

@JoshuaBehrens

kor3k avatar Nov 19 '22 19:11 kor3k

@kor3k thank you very much :)

JoshuaBehrens avatar Nov 19 '22 19:11 JoshuaBehrens