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

[9.x] Catch permission exception when creating directory #41871

Merged
merged 2 commits into from
Apr 7, 2022

Conversation

sebdesign
Copy link
Contributor

@sebdesign sebdesign commented Apr 7, 2022

Flysystem v3 throws an exception when attempting to create a directory that already exists, and the correct permissions cannot be set.

I have added the ['throws' => false] in my disks on the config/filesystems.php file.

For example, running Storage::makeDirectory('test') from artisan (console kernel) creates the test directory with the console user and appropriate permissions.
Then, running Storage::makeDirectory('test') from the web (http kernel), throws an exception because the directory exists, and attemps to change the permissions, while the web user is not the same as the console user, so it fails.

League\Flysystem\UnableToSetVisibility Unable to set visibility for file test. 
    vendor/league/flysystem/src/UnableToSetVisibility.php:33 League\Flysystem\UnableToSetVisibility::atLocation
    vendor/league/flysystem/src/Local/LocalFilesystemAdapter.php:422 League\Flysystem\Local\LocalFilesystemAdapter::setPermissions
    vendor/league/flysystem/src/Local/LocalFilesystemAdapter.php:320 League\Flysystem\Local\LocalFilesystemAdapter::createDirectory
    vendor/league/flysystem/src/Filesystem.php:96 League\Flysystem\Filesystem::createDirectory
    vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php:781 Illuminate\Filesystem\FilesystemAdapter::makeDirectory

Since Laravel allows to return false instead of throwing exceptions, this exception should be handled.

The same exception is already handled in the Storage::setVisibility() method.

Also, it should probably be handled in the writeStream and put methods?

@driesvints
Copy link
Member

Also, it should probably be handled in the writeStream and put methods?

Yes

@taylorotwell
Copy link
Member

Please mark as ready for review when other methods are updated.

@taylorotwell taylorotwell marked this pull request as draft April 7, 2022 14:01
@sebdesign sebdesign marked this pull request as ready for review April 7, 2022 14:37
@taylorotwell taylorotwell merged commit d2dce63 into laravel:9.x Apr 7, 2022
@taylorotwell
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

3 participants