Skip to content

[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

Closed
wants to merge 3 commits into from

Conversation

alquerci
Copy link
Contributor

QA
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#3585, #7834
License?MIT
  • Add a good detection of non seekable stream
  • Add some unit tests

But the iteration under ftp stream still not work properly. Edit: need tests for that.

@fabpot
Copy link
Member

fabpot commented May 23, 2013

is it possible to add some unit tests for that?

@alquerci
Copy link
Contributor Author

@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.

@alquerci
Copy link
Contributor Author

almost done

if ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
$innerIterator = $iterator->getInnerIterator();

if ($innerIterator instanceof RecursiveDirectoryIterator) {
Copy link
Contributor

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()) { 

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

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

fabpot added a commit that referenced this pull request May 25, 2013
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
@fabpot fabpot closed this May 25, 2013
@alquerci alquerci deleted the ticket-3585-7834 branch May 25, 2013 18:44
nicolas-grekas added a commit that referenced this pull request Jul 6, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants