4

I'm using Drupal 8 and the Flysystem module to configure remote file storage via SFTP. My question probably applies in general, though.

When a file is uploaded, and the file directory setting has a value, then Drupal creates a subdirectory if it doesn't already exist in the remote location. For example, the file directory defaults to [date:custom:Y]-[date:custom:m] to organize files by month. I need to set the permissions of these subdirectories. Currently, they're defaulting to 744. How do I change this? I'm hoping there is either a global setting, a hook, or a way to set the permissions in a module.

Thank you in advance for your help!

1 Answer 1

6

A standard Drupal would use Core's FileSystem class to create directories and set permissions according to the file_chmod_directory setting, which you can adjust within your site's settings.php files:

/**
 * Default mode for directories and files written by Drupal.
 *
 * Value should be in PHP Octal Notation, with leading zero.
 */
# $settings['file_chmod_directory'] = 0775;
# $settings['file_chmod_file'] = 0664;

It defaults to 0775 and is therefore commented out in a regular installation.

However, you mentioned using the Flysystem stream wrapper module. A short look into it's code reveals, that it is indeed using the FileSystem::CHMOD_DIRECTORY constant as default for local files. But the final directory permissions can vary depending on the Flysystem adapter plugin you are using. Something that is out of our control here at Drupal Answers. It's a contrib module anyway. So you will have to check yourself, of whether your adapter plugin supports the Core setting values/allows to configure it by other means. If not, you may wish to file an issue against the module that is providing the adapter you are using.

1
  • 1
    Thank you, Mario. This helped me find the solution. I traced the value of CHMOD_DIRECTORY to the adapter plugin code in the vendor directory and found a "directoryPerm" variable I can set in settings.php. Thanks again! Commented Aug 9, 2018 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.