thephpleague / flysystem

Abstraction for local and remote filesystems

Home Page:https://flysystem.thephpleague.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Local adapter private directory visibility

olegkhuss opened this issue · comments

Hi guys, can you confirm this is really a bug, I created a test to reproduce it and a possible fix

Bug Report

Q A
Flysystem Version 3.x
Adapter Name src/Local/LocalFilesystemAdapter.php
Adapter version 3.x

Summary

When I create a directory with ['visibility' => 'private'] config and retrieve visibility it returns me "public" but I expect it to be "private"

How to reproduce

git clone git@github.com:olegkhuss/flysystem.git .
composer install
vendor/bin/phpunit --filter="test_private_directory_visibility" src/Local/LocalFilesystemAdapterTest.php

The test above will fail, but I expect it to pass,

The test below will pass

git checkout fix/local_adapter_private_visibility
vendor/bin/phpunit --filter="test_private_directory_visibility" src/Local/LocalFilesystemAdapterTest.php

Hi, @olegkhuss this is intended behaviour. The directory permissions are write-mostly, as in, they have a second priority to the other methods. It can be part of a directory listing, but is not required. The visibility method is intended to be used for files, which is why you're getting an unexpected result. In practice, for file storage needs, directories are not super important. It's when people use Flysystem as an API for specific local filesystem operations that this is ...problematic.

@olegkhuss for clarity, V3 optimised a lot of paths to reduce the amount of expensive calls while retaining (almost) all functionality. It's better for the performance of your app and better for the environmental impact of running software to do less. This is why it changed.

It seems to me a bug still, the permissions in the filesystem are set correctly
but the code below doesn't return me the right value

$adapter = new LocalFilesystemAdapter(static::ROOT);

$adapter->createDirectory('public_directory', new Config(['visibility' => 'public']));
$publicVisibility = $adapter->visibility('public_directory');

$adapter->createDirectory('private_directory', new Config(['visibility' => 'private']));
$privateVisibility = $adapter->visibility('private_directory'); 

$this->assertEquals('public', $publicVisibility->visibility()); // okay
$this->assertEquals('private', $privateVisibility->visibility());  // ! failed, expect "private" but actual is "public"   

Now see the picture below, it returns me "public" in both cases whereas actual permissions are different?

image