Closed (fixed)
Project:
Drupal core
Version:
8.9.x-dev
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
17 Jan 2019 at 14:22 UTC
Updated:
12 Sep 2023 at 02:03 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
cilefen commentedTask?
Comment #3
alexpottHere's a start on this.
Comment #4
alexpottIndeed a task this is.
Comment #6
alexpottHo hum we changed the error handling to use exceptions.... so this works.
Comment #7
plachWould it make sense to mark this
@internal?\Drupal\Core\Archiver\Taris already acting as an adapter, kind of. This would allow us to avoid exposing the "actual" implementation (andPEAR) as a Drupal API.Comment #8
plachOne more thing, we are no longer using
\Drupal\Core\File\FileSystem::unlink()here: is this ok?Comment #9
alexpott@plach I'm not sure it would make sense for it to be internal...
We use it directly in controllers and forms that's not internal. We could have a follow-up to using the adapter instead but these things only support tar so I'm not sure. What would make sense is for this to final as there is no use-case to extend this class - you should extend the PEAR class but that is a contentious issue atm and does not need to be broached here. Plus we couldn't make this final in minor or patch release so moot atm.
Our unlink is specialised for windows - this is really really old code. And speaks to environment and core PHP issues rather than Drupal issues but also more modern PHP file system abstractions likehttps://github.com/symfony/filesystem don't do this for Windows and I really doubt that we need to. Also unlink Drupal, Symfony code is actually tested on Windows - see https://github.com/symfony/symfony/blob/master/.appveyor.yml
drupal_unlink() was added in #443286-25: Windows File Handling: International characters break file handling, permissions don't translate with little thought to the costs of maintaining this. There is also a comment saying we should have a link to the PHP bug - but unfortunately this is not there. There is also a comment saying that the fix should be filed upstream to ArchiveTar but it does not appear to have been. But also we have alot of calls to unlink already in vendor - for example in Twig and PhpUnit both of which are tested on Windows regularly outside of the Drupal and they don't contain this Windows work-around.
Personally I think it is fine to remove these calls and use the library as is apart from the move to exceptions.
Comment #10
alexpottRe the using the adapter - I think we could think about filing a follow-up for making all the usages in core use the adapter instead of the ArchiveTar directly.
Comment #11
plachCompelling argument :)
Ok, a follow-up works for me, given that people might already be using
ArchiveTarin contrib/custom code. But since now we are formally bringing in another external dependency (pear/*), I was hoping to find a way to decouple ourselves from it. Do we have a way to state that onlyArchiveTaris a Drupal API, not any of its parents? Could we makeArchiveTarwrap\Archive_Tarinstead of extending it?Comment #12
alexpott@plach For me we should file an issue to make all the controller / form could use our adapter... and then we can consider marking our ArchiveTar @internal in Drupal 9
I've tried to discovered if the PHP issue that caused us to create drupal_unlink() has been fixed. I found https://bugs.php.net/bug.php?id=42291&thanks=6 so far.
Comment #13
plachSounds good
Comment #14
alexpottCreated the follow-up - #3027290: Use \Drupal\Core\Archiver\Tar instead of \Drupal\Core\Archiver\ArchiveTar in controllers are forms
Comment #15
larowlanAfter the recent security issues with Pear and in particular pear.net, are we sure that going forward Pear is what we want to continue with?
I agree we should be offloading this code to another project but is Pear what we'd pick in 2019?
Comment #16
berdirThe code for pear projects has been on github for a long time, so installing them with composer is not related to that security issue in any way?
And no, maybe we wouldn't pick this library in 2019, but switching it with something else is a much bigger task than changing how we include it?
One thing I'm wondering is how much extra dependencies/code this results in, as it depends on the pear base stuff..
Comment #17
alexpottHere's what is included:
So what does this mean for core?
It means when we load ArchiveTar we include vendor/pear/pear-core-minimal/src/PEAR.php - some defines in main and it does
@ini_set('track_errors', true);and this is the only new code loaded. This code also defines two classes - Pear and PEAR_Error and function _PEAR_call_destructors(). We potentially call PEAR::loadExtension() but that is only if an extension is not loaded which will be rare and this code is very simple and we had copied it before. I don't think we have to much extra here.All told:
Whilst thinking about this I realised we need to remove the tests.
Comment #18
sam152 commentedWhich tests would be removed? I came here from #3026470: ArchiveTar is throwing fatal error and was going to suggest adding some basic integration tests for adding some files to an archive, extracting them and asserting the contents are the same.
I am working on a feature integrated into webform (like in the original issue), which zips up submissions, writes them to a file and then deletes the originals. The result for me was, a corrupt archive with uncatchable warnings and deleted submissions (not in production yet, thankfully :)).
I think I'll have to make my code a little more defensive and possibly attempt to extract the generated archive to assert it's valid before deleting the submissions, but I think that would have been avoided if core had tests for the class in the first place?
I realise we're not responsible for testing our upstream, but especially with conversations about superseding it and the fact that a bug snuck in before, it might be worth it?
Edit: adding a check which simply reads the contents of the archive was enough to catch the error in 8.6.7.
Comment #20
alexpottRandom JS test fails unrelated to this change.
Comment #21
panchoMarked #2610984: Add Archive Tar via Composer, with BC shim a duplicate, though actually this one here was created later.
Comment #27
alexpott@Pancho thanks for spotting that and doing the issue management. Crediting the contributors from that issue.
Comment #28
jibranDo we need a change record for adding new library?
Comment #29
alexpott@jibran I don't think so because what is changing? :) No one should need to make any changes due to this.
Comment #30
plach@jibran:
I don't think we should advertise PEAR as a newly available library, if that's what you meant. On the contrary I think we should have a policy in place that our vendor libraries should not be considered Drupal APIs and should not be covered by our BC policy. However discussing this will require a new issue, so I will stop ranting about that now ;)
Comment #31
jibranI agree we don't need a change record.
Comment #33
jibranComment #34
catch@Sam152 the tests being removed are the ones shipped with the library, we always remove those on the basis that upstream projects manage running their own test suites.
Committed 53c6cc8 and pushed to 8.7.x. Thanks!
Comment #36
kim.pepper🎉
Comment #38
xjmActually I agree with Jibran's first opinion; this should have had a change record. It could affect sites or custom code that have their own dependencies on it to know it's now managed in Composer. We also usually briefly mention dependency changes (including updates and new dependencies) in the release notes.
Comment #39
xjmAdded a release note to the IS.
Comment #42
quietone commentedAdded the CR. Can someone check it?
Comment #43
longwaveLooks correct to me, moving to RTBC but this can probably just be moved to Fixed?
Comment #44
longwaveChange record is done, followup exists as well (whether it's still relevant is another thing): #3027290: Use \Drupal\Core\Archiver\Tar instead of \Drupal\Core\Archiver\ArchiveTar in controllers are forms
Comment #45
andypostThanks 👍 looks proper status now
Comment #47
quietone commentedPublished the change record.