Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem
- When switching from the default PhpStorage\MTimeProtectedFileStorage to PhpStorage\FileStorage, you get this fatal error:
Warning: file_put_contents(sites/default/files/php/service_container/service_container_prod_.php): failed to open stream: Permission denied in Drupal\Component\PhpStorage\FileStorage->save() (line 60 of core\lib\Drupal\Component\PhpStorage\FileStorage.php). Drupal\Component\PhpStorage\FileStorage->save('service_container_prod_.php', '...
Cause
sites/default/files/php/service_container/service_container_prod_.php
is a directory.
Proposed solution
- Change MTimeProtectedFileStorage to not use a
.php
file suffix for its directory.
Comment | File | Size | Author |
---|---|---|---|
#10 | interdiff.txt | 1.18 KB | sun |
#10 | drupal8.phpstorage-directory-name.10.patch | 2.09 KB | sun |
#8 | drupal8.phpstorage-directory-name.8.patch | 2.03 KB | sun |
#5 | drupal8.phpstorage-directory-name.5.patch | 1.92 KB | sun |
#3 | drupal8.phpstorage-directory-name.3.patch | 1004 bytes | sun |
Comments
Comment #1
sunComment #2
sunComment #3
sunAttached patch fixes this issue.
Comment #5
sunGlad to see that there are tests :)
Comment #6
jibran5: drupal8.phpstorage-directory-name.5.patch queued for re-testing.
Comment #8
sunThis one should come back green.
Comment #9
znerol CreditAttribution: znerol commentedWe can safely leave out the reference to Windows, other OSes behave the same.
Instead of special-casing files with php extension, wouldn't it make sense to simply substitute the periods (we already do the same with slashes). E.g:
Comment #10
sunAdjusted the comment.
I'd prefer to keep the removal of the .php extension, because I think it's strange/awkward to have any kind of extension in a directory name to begin with (regardless of whether it's .php or #php).
Not sure about the concern of "special-casing" .php... — Technically PhpStorage only creates .php files, because that's it's only purpose. I only included the condition, because IIRC one of the unit tests writes/dumps a file without extension. If you feel strongly about that, then we could change the condition to use
strrpos($name, '.')
instead, so as to cut off any possibly existing file extension from the directory name.Comment #11
znerol CreditAttribution: znerol commentedOk, I'm fine with that. In fact the documentation on
PhpStorageInterface
suggests that file names are expected to have a .php suffix.I've reproduced the failure condition and verified the fix. This is good to go.
Comment #12
alexpottCommitted 241356f and pushed to 8.x. Thanks!