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

File owner / group / permissions #8

Open
smieruch opened this issue Dec 24, 2023 · 4 comments
Open

File owner / group / permissions #8

smieruch opened this issue Dec 24, 2023 · 4 comments

Comments

@smieruch
Copy link

Hi,
first of all, I would like to say thank you for this great package. I have successfully included it into a Laravel App. However, I wanted to ask if you can give me a hint to change the owner, the group and the file permissions for created and uploaded files and folders.
Thanks and kind regards,
Sebastian

@n1crack
Copy link
Owner

n1crack commented Dec 24, 2023

  1. Change Ownership:
    You can use the chown function to change the owner of a file. For example:
chown(storage_path('app/file.txt'), 'newOwner');
  1. Change Group:
    Similarly, you can use the chgrp function to change the group of a file:
chgrp(storage_path('app/file.txt'), 'newGroup');
  1. Change Permissions:
    To change the file permissions, you can use the chmod function:
chmod(storage_path('app/file.txt'), 0644);

Here, 0644 is an example of file permissions. You can customize it based on your requirements.

  1. Change Permissions Recursively for Folders:
    If you need to change permissions recursively for folders, you can use the recursive option in Laravel’s File facade:
File::chmodDirectory(storage_path('app/folder'), 0755, true);

The third parameter true indicates that the operation should be performed recursively.

Remember to replace 'newOwner', 'newGroup', 'file.txt', and 'folder' with the actual values and file/folder names you’re working with.

@smieruch
Copy link
Author

smieruch commented Dec 25, 2023

Thanks a lot for the detailed answer. However, in my app I have to access the files in the workspace with a certain user e.g. with uid=1000. By default the workspace is created with "drwx------ 3 www-data www-data". Files are created with "-rw-r--r-- 1 www-data www-data". Now I would need to place a hook into the VueFinder.php on every file / folder create / change and change the permissions or owner or group. I think this is not the best way to do it.

So, I'm wondering if there is rather a global setting for the permissions. From Laravel I could do this:

'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'permissions' => [
'file' => [
'public' => 0644,
'private' => 0600,
],
'dir' => [
'public' => 0755,
'private' => 0700,
],
],
],

Maybe this is the solution, I have to try. I could change the permissions to 0777, then my user with uid=1000 has full access. But still owner:group is www-data:www-data.

Ok I have to try.

Cheers.

@smieruch
Copy link
Author

Ok, I tried that, but it only has an effect on Laravel's Storage, e.g. creating a file
Storage::disk('local')->put($private_workspace . '/example.txt', 'Contents');
It seems to have no effect on VueFinder.
Do you have an idea how I could change permissions globally for VueFinder creating files etc. to e.g. 0777 ?
Thanks.

@smieruch
Copy link
Author

smieruch commented Jan 6, 2024

Hi,
I found a solution for my usecase. First I change the umask to umask(0000) according to https://www.php.net/manual/en/function.umask.php
Then I have added a few lines to the PHP following https://flysystem.thephpleague.com/docs/usage/unix-visibility/

//add PortableVisibilityConverter                                                                                                                                    
use League\Flysystem\UnixVisibility\PortableVisibilityConverter;

//set umask                                                                                                                                                          
umask(0000);

// Set VueFinder class                                                                                                                                               
$vuefinder = new VueFinder([
    'local' => new LocalFilesystemAdapter(
        dirname(__DIR__).'/storage',
	PortableVisibilityConverter::fromArray([
            'file' => [
            'public' => 0777,   //no effect                                                                                                                          
            'private' => 0777,  //no effect                                                                                                                          
            ],
            'dir' => [
            'public' => 0777,
            'private' => 0777,    //this is used                                                                                                                     
            ],
	]),
    ),
]);

The crucial point is to set the umask. I don't understand it fully, the PortableVisibilityConverter has no effect on files, but on private folders. Anyway for files the new umask is used, which is 666 (-rw-rw-rw-). For folders it is 777 (drwxrwxrwx). Still owner and group is www-data. This works now for me, I can access the files and folders with another user.

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

No branches or pull requests

2 participants