-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Finder] Fix iteration fails with non-rewindable streams #8120
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
Conversation
is it possible to add some unit tests for that? |
@fabpot I think it's possible to add some unit tests. But what is your opinion about that. If a non-seekable streams does not work. Should it be explicitly unsupported ? There is maybe a solution that is to make it virtually seekable by adding a wrapper that stores all SplFileInfo object. But this is another story. |
almost done |
if ($iterator->getInnerIterator() instanceof \FilesystemIterator) { | ||
$innerIterator = $iterator->getInnerIterator(); | ||
|
||
if ($innerIterator instanceof RecursiveDirectoryIterator) { |
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 ($innerIterator instanceof RecursiveDirectoryIterator && $innerIterator->isRewindable()) {
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.
RecursiveDirectoryIterator
is a \FilesystemIterator
so your fix does not have the same behaviour.
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.
This is not a real "fix" it CS fix.
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.
@stloyd your suggestion is not a CS fix as the suggested code does not have the same behavior than the current code of the PR. Combining both conditions together changes what goes through the elseif
This PR was squashed before being merged into the 2.1 branch (closes Discussion ---------- [Finder] Fix iteration fails with non-rewindable streams <table> <tr> <th>Q</th><th>A</th> </tr> <tr> <td>Bug fix?</td><td>yes</td> </tr> <tr> <td>New feature?</td><td>no</td> </tr> <tr> <td>BC breaks?</td><td>no</td> </tr> <tr> <td>Deprecations?</td><td>no</td> </tr> <tr> <td>Tests pass?</td><td>yes</td> </tr> <tr> <td>Fixed tickets</td><td>#3585, #7834</td> </tr> <tr> <td>License?</td><td>MIT</td> </tr> </table> - [x] Add a good detection of non seekable stream - [x] Add some unit tests But the iteration under ftp stream still not work properly. Edit: need tests for that. Commits ------- 169c0b9 [Finder] Fix iteration fails with non-rewindable streams
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Finder] Fix initial directory is opened twice | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #50851 | License | MIT | Doc PR | no The issue was introduced in #8120 which was coded wrongly for several reasons: - `seekable` support is about file/stream content seeking, not about rewind support, non-seekable stream handler can support rewind - it worked by coincidence - the original code involved additional directory open (syscall), which is/was slow - 1st rewind of DirectoryIterator is implicit, ie. it is not needed - again, skipping the rewind worked by coincidence - 2nd+ rewind must fail if it is not supported, the original code silently skipped it The test from #8120 is kept and is passing. I also improved the ftp support detection to make the test stricter. To support rewind for ftp I opened - php/php-src#11597 - but this Symfony PR does not need it. Commits ------- d3f03be [Finder] Fix initial directory is opened twice
But the iteration under ftp stream still not work properly. Edit: need tests for that.