Problem/Motivation
There are scenarios where a failure is reported when perform various composer commands such ascomposer require
[RuntimeException]
Could not delete /path/web/sites/default/default.services.yml:
...
Installation failed, reverting ./composer.json to its original content.
#3103090: Avoid re-scaffolding unchanged files (and printing scaffold file information over and over) has been merged. This should take care of the symptom historically described in this issue in most instances, as least when using drupal/{recommended,legacy}-project without any additional scaffold files. In that scenario, the only time the failure reported in this issue should be seen is:
- The site builder modifies
sites/default/default.services.yml
orsites/default/default.settings.php
. (Should be rare, as these files should be copied before they are modified.) - The site builder removes
sites/default/default.services.yml
orsites/default/default.settings.php
. - Whenever Drupal core changes either file:
$ git log --pretty=format:"%ad%x09%<(25,trunc)%s" -n 10 origin/10.1.x -- sites/default/default.* Wed Apr 19 11:18:37 2023 -0500 SA-CORE-2023-005 by ben.. Tue Apr 11 14:10:23 2023 +0100 Issue #3027639 by catch.. Sun Mar 12 20:06:51 2023 +0000 Issue #3107548 by tunic.. Mon Mar 6 17:14:57 2023 +0000 Issue #3150614 by pfren.. Fri Mar 3 16:08:14 2023 +0000 Revert "Issue #3150614 .. Fri Mar 3 11:13:53 2023 +0000 Issue #3150614 by pfren.. Thu Feb 23 16:22:19 2023 +0000 Issue #3317265 by ressa.. Thu Feb 23 10:20:36 2023 +0000 Issue #3198868 by dpi, .. Thu Feb 16 22:36:17 2023 +0000 Issue #3333281 by Musta.. Wed Nov 30 17:35:34 2022 +0000 Issue #3032746 by mfb, ..
Doing either of these things will cause the next scaffold operation to fail.
Current workaround
The best workaround today is still as per #52 (although n.b. the filename is wrong in that comment).
"drupal-scaffold": {
"locations": {
"web-root": "web/"
},
"file-mapping": {
"[web-root]/sites/default/default.services.yml": false,
"[web-root]/sites/default/default.settings.php": false
}
},
Proposed resolution
We could still continue with this patch in order to improve the scaffolding operation such that these workarounds are not necessary. If someone wanted to move this forward, my comments in #43 still apply.
Rather than adding so many parameters to control the behavior of the replace and append ops as proposed historically, perhaps a simpler strategy of simply trying harder would be appropriate. i.e. the scaffold plugin could always try to make a write-protected file writable first, and only fail if it does not have permission to do that.
Option A:
The scaffolding could try to `chmod` unwritable files before the operations themselves were called to attempt to write their contents.
Option B:
We could introduce the concept of an "optional" scaffold file (e.g. default.settings.php, README.txt, etc), and reduce permission denied errors to warnings for those files.
Remaining tasks
[ ] Implement option A and maybe option B
Follow-on tasks
[ ] #3092563: Avoid overwriting .htaccess changes during scaffolding > security problem
User interface changes
This should result in better and less warnings/errors during scaffolding
API changes
None
Data model changes
None, unless "option B" implemented.
Release notes snippet
Older description for historical context
If you've installed and run Drupal, the sites/default directory receives permission hardening. This can break the scaffolding plugin.
[RuntimeException]
Could not delete /path/web/sites/default/default.services.yml:
composer require drupal/openapi drupal/openapi_ui drupal/openapi_ui_redoc drupal/schemata
1/1: http://repo.packagist.org/p/provider-latest$46a92f2b264b89accfae0d6579f9b6e022c87a70701dad793daf7963e2bf31df.json
Finished: success: 1, skipped: 0, failure: 0, total: 1
Using version ^1.0@beta for drupal/openapi
Using version ^1.0@RC for drupal/openapi_ui
Using version ^1.0@RC for drupal/openapi_ui_redoc
Using version ^1.0@beta for drupal/schemata
./composer.json has been updated
Gathering patches for root package.
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 5 installs, 0 updates, 0 removals
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
- Installing drupal/schemata (1.0.0-beta1): Loading from cache
- Installing drupal/schemata_json_schema (1.0.0-beta1)
- Installing drupal/openapi (1.0.0-beta6): Loading from cache
- Installing drupal/openapi_ui (1.0.0-rc2): Loading from cache
- Installing drupal/openapi_ui_redoc (1.0.0-rc2): Loading from cache
Writing lock file
Generating autoload files
Scaffolding files for drupal/core:
- Copy [project-root]/.editorconfig from assets/scaffold/files/editorconfig
- Copy [project-root]/.gitattributes from assets/scaffold/files/gitattributes
- Copy [web-root]/.csslintrc from assets/scaffold/files/csslintrc
- Copy [web-root]/.eslintignore from assets/scaffold/files/eslintignore
- Copy [web-root]/.eslintrc.json from assets/scaffold/files/eslintrc.json
- Copy [web-root]/.ht.router.php from assets/scaffold/files/ht.router.php
- Copy [web-root]/.htaccess from assets/scaffold/files/htaccess
- Copy [web-root]/example.gitignore from assets/scaffold/files/example.gitignore
- Copy [web-root]/index.php from assets/scaffold/files/index.php
- Copy [web-root]/INSTALL.txt from assets/scaffold/files/drupal.INSTALL.txt
- Copy [web-root]/README.txt from assets/scaffold/files/drupal.README.txt
- Copy [web-root]/robots.txt from assets/scaffold/files/robots.txt
- Copy [web-root]/update.php from assets/scaffold/files/update.php
- Copy [web-root]/web.config from assets/scaffold/files/web.config
- Copy [web-root]/sites/README.txt from assets/scaffold/files/sites.README.txt
- Copy [web-root]/sites/development.services.yml from assets/scaffold/files/development.services.yml
- Copy [web-root]/sites/example.settings.local.php from assets/scaffold/files/example.settings.local.php
- Copy [web-root]/sites/example.sites.php from assets/scaffold/files/example.sites.php
Installation failed, reverting ./composer.json to its original content.