Problem/Motivation
When running the test suiet, specifically unit tests) as a user with write permissions to the Drupal root directory, the test suite creates a vfs:
directory in the Drupal root.
The problem is caused by some code in Drupal\Component\PhpStorage\FileStorage
that makes the assumption that when recursing a path at least one part of the path will exist because at some point it will reach the root of the filesystem.
Unfortunately the way this is implemented and the assumption itself can fail for streams like vfs used in the tests.
Proposed resolution
Refactor the Drupal\Component\PhpStorage\FileStorage::createDirectory
method to make it more resilient to streams.
Remaining tasks
Patch
Tests
Reviews
User interface changes
n/a
API changes
n/a
Data model changes
n/a
Original report by neclimdul
Been meaning to take a look at this for... years? It happens, it should not happen, now there's an issue.
Comment | File | Size | Author |
---|---|---|---|
#9 | 2979150-9-fixFileStorageTest.interdiff.txt | 898 bytes | neclimdul |
#9 | 2979150-9-fixFileStorageTest.patch | 3.46 KB | neclimdul |
Comments
Comment #2
neclimdulHere's a solution. Updated IS with description of the problem.
Comment #3
neclimdulComment #6
neclimdulStill an issue... Fix still works...
Comment #8
jhedstromThis makes sense to me. I think it looks good to go, just a few nits:
Nit: should this use
===
?Nit: This should be above the code line, and end in an '.' I think...
Comment #9
neclimdulGoodness me, I don't really remember writing this anymore so I don't know why I chose == vs === but I can't see a reason not to. And yeah that comment is terribly placed. Again, no excuse :)
The comment isn't even that clear. I read through it a couple times and I think this version makes the logic a little clearer.
Thanks!
Comment #10
jhedstromI was trying to manually reproduce this issue. I ran
vendor/bin/phpunit -c core/phpunit.xml core/tests/Drupal/Tests/Core/File/
but novfs:
directory is created in the root directory...Comment #11
neclimdulI don't think that test was actually creating the directory but something else using the FileStorage class maybe not even directly. I don't remember if I ended up getting to the bottom of that but probably not since I didn't put it in the summary. If you run the full unit testsuite you should see it but I'll have to dig in to find which exact tests are causing this.
Comment #12
jhedstromOk, confirmed that running the entire test suite creates the
vfs:
directory. Also confirmed the tests in this patch fail (the directory is created) without the corresponding fix. Given that, I think this looks good to go.Comment #13
alexpottGiven this is extremely low level code I'd like to make this change in the smallest possible performance impact as possible.
Can I suggest we change the patch to do:
That way we only parse the URL when the directory doesn't exist which is the only time we actually need to.
And maybe we should consider doing something to not have to parse the directory all the times during a recursive call. Note this method is called a lot during a twig file cache rebuild.