config->write() currently uses file_put_contents() to write files, withour calling drupal_chmod() to look after the permissions of those files. Presumably that was done because drupal_chmod() depended on config. This patch moves the chmod variables to the settings system so that they are available very early, like when we write out config files during the installer.

The main benefit here is that config files can now be writable by both webserver and cli user and thus all sorts of drush commands are able to work without disrupting web admin users (config commands, pm-enable, ...).

This patch enables us to roll back #2099467: Let non-interactive installers determine mode of files directory and its subdirectories as it is this patch fixes that need, and more.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch, chmod.diff, failed testing.

moshe weitzman’s picture

Status: Needs work » Needs review
FileSize
11.17 KB

Fix install bug I hope

Status: Needs review » Needs work

The last submitted patch, chmod.diff, failed testing.

moshe weitzman’s picture

Status: Needs work » Needs review
FileSize
11.92 KB

Fixed the fails. The warnings from he Upgrade tests are eluding me. I could use some help here The upgrade tests do some fun cleverness that is giving harmless warning it seems.

Status: Needs review » Needs work

The last submitted patch, chmod.diff, failed testing.

chx’s picture

I think the removal of upgrade tests will help.

moshe weitzman’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
11.73 KB

Just a reroll. Let's see.

Status: Needs review » Needs work

The last submitted patch, 7: chmod.diff, failed testing.

moshe weitzman’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: +Configuration system
FileSize
21.16 KB

Simplified a little since stream wrappers are not declared when we are writing config in installer. Also included a rollback of #2099467: Let non-interactive installers determine mode of files directory and its subdirectories as promised in the Summary. That code is no longer needed.

The attached format-patch has 2 commits in it so folks can see the new code separate from the rollback, and still get it all tested by the bot.

moshe weitzman’s picture

Issue summary: View changes
moshe weitzman’s picture

FileSize
21.77 KB

Now with 2 new assertions which validate that these settings work.

sun’s picture

  1. +++ b/core/includes/file.inc
    @@ -42,6 +42,17 @@
    +const CHMOD_DEFAULT_DIRECTORY = '0775';
    ...
    +const CHMOD_DEFAULT_FILE = '0664';
    

    1. Can we define the constant values are octals instead of strings?

    2. I think the constant names should be prefixed with "FILE_". And because they're constants, I'm not sure whether the "DEFAULT_" in their names is required? How about these:

    FILE_CHMOD_DIRECTORY
    FILE_CHMOD_FILE

    3. Do we actually know why we're diverging from the PHP defaults? (at least mkdir() defaults to 0777)

  2. +++ b/sites/default/default.settings.php
    @@ -450,6 +450,14 @@
    + * Value should be a string in PHP Octal Notation.
    

    Given that the values are moved entirely out of the config system and are only ever set in PHP now, the entire string to octdec() conversion appears to be obsolete?

    Consuming code either gets the setting from settings.php (PHP) or the constant value from file.inc (PHP).

    Thus, there are no more strings anywhere at all and we can use raw octals everywhere?

  3. +++ b/sites/default/default.settings.php
    @@ -450,6 +450,14 @@
    +# $settings['file_chmod_directory'] = '0775';
    +# $settings['file_chmod_file'] = '0664';
    

    Given that we also plan to move the private/temporary filesystem paths into settings, I'm a bit concerned about the resulting DX in settings.php — we'll end up with this:

    $settings['file_chmod_directory'] = ...;
    $settings['file_chmod_file'] = ...;
    $settings['file_public_path'] = ...;
    ...
    

    I wonder whether we're able to plan ahead of time already?

    In an ideal world, I think I'd consider this:

    $settings['file_chmod_directory'] = ...;
    $settings['file_chmod_file'] = ...;
    $settings['stream']['public'] = ...;
    $settings['stream']['private'] = ...;
    $settings['stream']['temporary'] = ...;
    ...
    

    Hm. Actually, the proposed $settings keys here appear to be fine, since they're not related to stream wrappers - or much rather, they apply to all local filesystem stream wrappers.

    That said, to underline 1.2, a naming consistency between $settings['file_chmod_directory'] and the FILE_CHMOD_DIRECTORY constant would make most sense to me.

moshe weitzman’s picture

FileSize
21.5 KB

Simplified per 1,2 in Sun's review.

sun’s picture

Status: Needs review » Reviewed & tested by the community

This looks ready to me, in case testbot comes back green.

moshe weitzman’s picture

Assigned: moshe weitzman » alexpott

Alex worked with me on #2099467: Let non-interactive installers determine mode of files directory and its subdirectories in Prague so perhaps he should preside over its rollback.

alexpott’s picture

Assigned: alexpott » Unassigned

Looks like a sensible and better approach than #2099467: Let non-interactive installers determine mode of files directory and its subdirectories - this is committable once major and critical week is over

webchick’s picture

Assigned: Unassigned » alexpott

Looks like Alex has got this.

alexpott’s picture

Priority: Normal » Major
Status: Reviewed & tested by the community » Active
Issue tags: +Needs change record

Committed a3c8c88 and pushed to 8.x. Thanks!

I think we need a change notice to explain how it is different from Drupal 7.

j4’s picture

Status: Active » Needs review
alexpott’s picture

@j4 the point of the change notice is to tell people how this was configured in Drupal 7

  $dir_mode = variable_get('file_chmod_directory', 0775);
  $file_mode = variable_get('file_chmod_file', 0664);

Is now...

  $dir_mode = settings()->get('file_chmod_directory', FILE_CHMOD_DIRECTORY);
  $file_mode = settings()->get('file_chmod_file', FILE_CHMOD_FILE);

in Drupal 8

Also the reason we are making this change is because the variable system is being replace by configuration stored in files and, therefore, we can not store this in configuration.

j4’s picture

Have added this. Sorry this was my first time in trying to create change records..thank you for the explanation.

Jaya

geerlingguy’s picture

I'm not 100% sure if this is related to my issue or not, as I haven't had tons of time to dig... but if I use Drush (latest master version from GitHub) and download drupal-8.x dev, then do a drush site-install, the install completes successfully, and drush status works perfectly, but Drupal keeps giving me the 'you probably need to rebuild' message.

I tracked it down to the settings.php file having 444 permissions—if I switched to 744, then loaded the page again, everything worked great. I went back to 444 after that, and things kept working. So it seems if I do a drush site-install, then pop over to the web browser, some final thing needs to be written to settings.php but can't be.

Until I updated those permissions, I got the rebuild message in the browser, and the following in Apache's error log:

PHP Fatal error:  Call to undefined function cache() in /var/www/drupal-8.x-dev/core/includes/module.inc on line 33

Maybe drush site-install is where the problem lies? I have no idea, but will investigate later if I'm able.

moshe weitzman’s picture

Title: Move chmod.directory and chmod.file out of config and into settings so that file writes are independant of the config system » Move file_chmod_directory and file_chmod_file out of config and into settings so that drush_chmod() is independant of the config system
Status: Needs review » Fixed

Update title to match patch that was committed. Also updated the change record a bit.

@geerlingguy - please do share your findings if you get back to debugging your issue.

geerlingguy’s picture

@moshe - will do. For now, I've left comments everywhere someone else might find potential solutions, hopefully that helps others who get stuck in the same rut.

xjm’s picture

Title: Move file_chmod_directory and file_chmod_file out of config and into settings so that drush_chmod() is independant of the config system » Change record: Move file_chmod_directory and file_chmod_file out of config and into settings so that drush_chmod() is independant of the config system
Status: Fixed » Needs work

The change record here could use a bit of work. Before-and-after examples for D7 and D8 would be very helpful, and the text is not very clear.

xjm’s picture

Issue tags: +Missing change record
moshe weitzman’s picture

Title: Change record: Move file_chmod_directory and file_chmod_file out of config and into settings so that drush_chmod() is independant of the config system » Move file_chmod_directory and file_chmod_file out of config and into settings so that drush_chmod() is independant of the config system
Assigned: alexpott » Unassigned
Status: Needs work » Fixed
Issue tags: -Needs change record, -Missing change record

Cleaned up change record.

benjy’s picture

This issue introduce a bug in file_unmanaged_copy() https://drupal.org/node/2191631

benjy’s picture

Sorry, it looks like the bug has been around for a while. I wrongly presumed it was this patch that caused the issue since it was so recent and the bug seemed like something that would have been caught fairly quick.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

sun’s picture