swayok / alternative-laravel-cache

Replacements for Laravel's redis and file cache stores that properly implement tagging idea
MIT License
170 stars 27 forks source link

Permissions are not respected #21

Closed RdeWilde closed 3 years ago

RdeWilde commented 4 years ago

In the readme.md file is an example on passing the permissions-configuration for file-based cache drivers in config/cache.php

I did literally copy the example code and change both public permissions to 0777, but files and directories are still being created with 644 etc. I recreated the config, so it is not a cached config. Also looked at #9 but that did not provide a solution.

Any clue? Any info I should provide?

        'file' => [
            'driver' => 'file',
            'path' => storage_path('framework/cache/data'),
            'permissions' => [
                'file' => [
                    'private' => 0777,
                    'public' => 0777,
                ],
                'dir' => [
                    'private' => 0777,
                    'public' => 0777,
                ],
            ]
        ],

When I dump $cacheConfig in makeFileCacheAdapter from AlternativeCacheStoresServiceProvider.php, I do get the right values:

array:2 [▼
  "file" => array:2 [▼
    "private" => 511
    "public" => 511
  ]
  "dir" => array:2 [▼
    "private" => 511
    "public" => 511
  ]
]

Also in vendor/league/flysystem/src/Adapter/Local.php::__construct I get the right values

swayok commented 4 years ago

PHP downgrades your permissions if you haven't disabled this feature manually. It is required to add umask(0000); somewhere before cache is used. I usually add this to bootstrap/app.php. Check your code for umask - if it is not set or not 0000 - then this is the reason why 0777 permissions are ignored

RdeWilde commented 4 years ago

Thanks for your fast response @swayok I understand what you are saying. When I look in the Local-adapter it seems to already reset the umask: https://github.com/thephpleague/flysystem/blob/1.x/src/Adapter/Local.php#L101

I also replaced the permissionMap with a static 0777 value - https://github.com/thephpleague/flysystem/blob/1.x/src/Adapter/Local.php#L103 - the directories were created, but still not with 0777 permissions.

Do you know what I can look at next?

RdeWilde commented 4 years ago

Listing for reference, possibly related: https://github.com/thephpleague/flysystem/issues/1181 I am using 1.1.3 though, so won't fix my problem

RdeWilde commented 4 years ago

Might still be an issue with PHP (config). I added this as first line to my index.php

umask(0);
@mkdir('test', 0777, true);

Still the directory is not created with 777-permission.

guess it is not related to your code.

swayok commented 4 years ago

This is quite strange. umask is the only thing that controls permissions in PHP as I know. Try to do @rmdir('test') to be sure directory not exists before creaton. @mkdir('test', 0777, true); will not change permissions if directory already exists. And also try chmod('test', 0777); after creation. Maybe something wrong with mkdir. If directory is still not 0777 - then it probably OS config somehow alters permissions.

RdeWilde commented 4 years ago

chmod does work, without it - it does not. But obviously this is not default implemented in the vendor's code. Thanks for your help, I'll keep digging.

swayok commented 4 years ago

Just to clarify - do you delete created folder each time you run the script?

RdeWilde commented 4 years ago

No

swayok commented 4 years ago

That is the reason why permissions are not updated unless you call chmod('test', 0777);. @mkdir('test', 0777, true); will never change permissions on already existing folder. Try his code:

@rmdir('test');
umask(0);
@mkdir('test', 0777, true);

Now directory should have 0777 permissions. If not - look for PHP or Linux restrictions.

Also this might be the reason why your cache folder haven't changed permissions according to config changes. If folder was created with 0755 permissions - then it will not ever change this permissions unless you delete it or use chmod on it.