-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev/core#2927 - Avoid warnings for is_dir() when open_basedir is in effect #22107
Conversation
(Standard links)
|
Jenkins re test this please |
This makes sense to me to use this approach. A follow-up would be to replace some calls to |
Thanks. I'll clean up and rebase. |
f484e50
to
0c551b8
Compare
CRM/Utils/File.php
Outdated
catch (\ErrorException $e) { | ||
$is_dir = FALSE; | ||
} | ||
restore_error_handler(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should restore_error_handler();
be inside a finally{}
block?
0c551b8
to
68b8eb9
Compare
Finally I get to use one of those. Yes that's a good idea. |
Very thorough test cases! Merging. |
Thanks! |
Overview
https://lab.civicrm.org/dev/core/-/issues/2927
Alternate approach to #21923 and #21592
There are situations where you don't have control over open_basedir, and civi will sometimes iterate over folders trying to find something and will hit ones outside open_basedir. This produces lots of notices. This approach uses a local error-handler to silence only messages about open_basedir while still keeping all the functionality of the real is_dir.
Before
After
With this PR, you'll still get one notice because for demonstration purposes I've only replaced is_dir() in one file, but you won't see the other notices.
Technical Details
I believe this has an advantage over the previous approaches because (a) it only silences open_basedir, and (b) it doesn't require trying to duplicate some of the core php functionality.
Comments
Has test, which is largely based on php's own tests for is_dir. This should ensure that if somebody changes the new isDir function it should still conform to the same results as the real is_dir() except of course complaining about open_basedir.
As I've noted in the function comment, there are times when you DO want to know about this error, because you're expecting that the folder either should exist or be usable, and so it suggests something else is wrong and without the error it might be harder to track down or know something is wrong. So this function shouldn't be used everywhere is_dir() is used, just in places where you know it might legitimately be reaching outside open_basedir.