-
Notifications
You must be signed in to change notification settings - Fork 29
Handle realpath()/getRealPath() failures
#1663
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
Open
bpfoley
wants to merge
1
commit into
DistributedProofreaders:master
Choose a base branch
from
bpfoley:level-7-realpath
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If
$real_pathis false here the file doesn't exist (which I'm unclear on how that can actually be possible given thatRecursiveIteratorIteratorjust told us about it, but let's humor PHPstan's paranoia about race conditions) and it would be clearer tocontinuethan try to do something with the file / directory.Changes like this seem like we're trading readability for PHPstan's paranoia.
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.
PHPStan knows nothing about race conditions or the inner workings of PHP's
realpath, all it knows is the function signature in one of its stub files. Unfortunately, the underlying libc functionrealpath()can fail for a variety of (admittedly unlikely) reasons even if the file/directory does exist. PHP returnsfalsein those cases. See https://man7.org/linux/man-pages/man3/realpath.3.html#ERRORSI'm not sure silently suppressing the error with
if ($real_path === false) continue;is the right thing to do, especially if the reason is that something else on the system has caused the directory to be inaccessible (eg a sysadmin doingchmod 0on the uploads directory). In that caserealpathwould silently fail multiple times potentially leaving an unflattened directory behind it. But given the aim is to get PHPstan level 7 working so we can detect more useful missing error handling, I don't really mind too much what way we handle this.