Skip to content

[2.0][Finder] Iteration fails with non-rewindable streams #3585

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
igorw opened this issue Mar 13, 2012 · 9 comments
Closed

[2.0][Finder] Iteration fails with non-rewindable streams #3585

igorw opened this issue Mar 13, 2012 · 9 comments

Comments

@igorw
Copy link
Contributor

igorw commented Mar 13, 2012

The finder docs mention iterating over an FTP stream, like so:

$finder->in('ftp://example.com/pub/');

Turns out, this does not work. It errors out with:

[ErrorException]
Warning: FilesystemIterator::rewind(): stream does not support seeking in foo.php line 42

Other stream wrappers may be affected as well.

Looks like @krachot already mentioned this somewhere a year ago.

@igorw
Copy link
Contributor Author

igorw commented Mar 13, 2012

This is already an issue when trying to use a FilesystemIterator with the ftp stream wrapper. So maybe the fix is to remove this example from the docs and file the ticket to PHP.

@stealth35
Copy link
Contributor

Just add :

<?php
if (false === stream_is_local($dir)) {
    $iterator = new \NoRewindIterator($iterator);
}

@igorw
Copy link
Contributor Author

igorw commented Mar 13, 2012

I tried adding that after the following lines in Finder.php:

$iterator = new \RecursiveIteratorIterator(
    new Iterator\RecursiveDirectoryIterator($dir, $flags),
    \RecursiveIteratorIterator::SELF_FIRST
);

But it looks like one of those iterators depends on rewinding. The initial FTP connection succeeds, but then it just lists the first file twice and errors out again with the same error message.

@fabpot
Copy link
Member

fabpot commented Mar 13, 2012

adding this just before returning the iterator does not work either. It just always returns an empty result.

@stealth35
Copy link
Contributor

Work for me with : https://gist.github.com/2028995

<?php
use Symfony\Component\Finder\Finder;

$finder = new Finder();
$finder->files()->in('ftp://ftp.mozilla.org/');

foreach ($finder as $file) {
    var_dump($file);
}

but not sure if next work with every other wrapper

@fabpot
Copy link
Member

fabpot commented Mar 13, 2012

It does not work in all cases, for instance if you add a depth:

Catchable fatal error: Argument 1 passed to Symfony\Component\Finder\Iterator\DepthRangeFilterIterator::__construct() must be an instance of RecursiveIteratorIterator, instance of NoRewindIterator given, called in /Users/fabien/work/symfony/git/symfony/src/Symfony/Component/Finder/Finder.php on line 474

@stealth35
Copy link
Contributor

Anyway the ftp wrapper open a connection for each folder.

I see two solutions her :

  • block the distant wrappers (with stream_is_local)
  • create a RecursiveFtpDirectoryIterator base on the ftp extension

@gajdaw
Copy link
Contributor

gajdaw commented May 21, 2012

Here is the first stage of my implementation of RecursiveDirectoryFtpIterator:

#4354

It works with filters (->depth() etc.)

@fabpot
Copy link
Member

fabpot commented Jun 19, 2012

see #4335

@fabpot fabpot closed this as completed Jun 19, 2012
fabpot added a commit that referenced this issue 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
craigmarvelley pushed a commit to craigmarvelley/symfony that referenced this issue Nov 26, 2013
Commits
-------

3eb67fc [2.1][Component][Finder] $this->current() fix

Discussion
----------

[2.1][Component][Finder] $this->current() fix

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: [![Build Status](https://secure.travis-ci.org/gajdaw/symfony.png?branch=master)](http://travis-ci.org/gajdaw/symfony)
Fixes the following tickets: -
Todo: -
License of the code: MIT

One method to resolve `->in("ftp://...")` problem is to create `RecursiveDirectoryFtpIterator`.
(Details: [issue 3585](symfony#3585))

I think that all filters should access the information about current item calling `current()` or `getInnerIterator()`. Otherwise it will not work if we replace `RecursiveDirectoryIterator` with ftp iterator inside `Finder`.

I'm not sure if that should go to 2.0 or 2.1 branch.

---------------------------------------------------------------------------

by travisbot at 2012-05-19T09:20:19Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1373361) (merged 9f247921 into 58b9245).

---------------------------------------------------------------------------

by gajdaw at 2012-05-19T10:51:10Z

Probably it should go to master branch, because it improves commit done to master:

symfony@f2fea97

---------------------------------------------------------------------------

by travisbot at 2012-05-19T11:26:14Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1373982) (merged f9d1db8c into 58b9245).

---------------------------------------------------------------------------

by travisbot at 2012-05-19T11:51:25Z

This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1374031) (merged f1b4b4f7 into 58b9245).

---------------------------------------------------------------------------

by travisbot at 2012-05-19T12:48:17Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1374303) (merged b6d073da into 58b9245).

---------------------------------------------------------------------------

by travisbot at 2012-05-19T13:28:18Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1374568) (merged fd144c96 into 58b9245).

---------------------------------------------------------------------------

by travisbot at 2012-05-19T13:35:38Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1374609) (merged 89a8d851 into 58b9245).

---------------------------------------------------------------------------

by travisbot at 2012-05-21T04:31:46Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1385764) (merged 0d5b8322 into 58b9245).

---------------------------------------------------------------------------

by travisbot at 2012-05-21T07:21:56Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1386545) (merged 3eb67fc into 1407f11).

---------------------------------------------------------------------------

by stof at 2012-06-09T13:24:14Z

seems good
joshtrichards pushed a commit to joshtrichards/symfony-finder that referenced this issue Apr 26, 2024
Commits
-------

3e1d3b8 [2.1][Component][Finder] $this->current() fix

Discussion
----------

[2.1][Component][Finder] $this->current() fix

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: [![Build Status](https://secure.travis-ci.org/gajdaw/symfony.png?branch=master)](http://travis-ci.org/gajdaw/symfony)
Fixes the following tickets: -
Todo: -
License of the code: MIT

One method to resolve `->in("ftp://...")` problem is to create `RecursiveDirectoryFtpIterator`.
(Details: [issue 3585](symfony/symfony#3585))

I think that all filters should access the information about current item calling `current()` or `getInnerIterator()`. Otherwise it will not work if we replace `RecursiveDirectoryIterator` with ftp iterator inside `Finder`.

I'm not sure if that should go to 2.0 or 2.1 branch.

---------------------------------------------------------------------------

by travisbot at 2012-05-19T09:20:19Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1373361) (merged 9f247921 into 58b92453).

---------------------------------------------------------------------------

by gajdaw at 2012-05-19T10:51:10Z

Probably it should go to master branch, because it improves commit done to master:

symfony/symfony@e553c49

---------------------------------------------------------------------------

by travisbot at 2012-05-19T11:26:14Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1373982) (merged f9d1db8c into 58b92453).

---------------------------------------------------------------------------

by travisbot at 2012-05-19T11:51:25Z

This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1374031) (merged f1b4b4f7 into 58b92453).

---------------------------------------------------------------------------

by travisbot at 2012-05-19T12:48:17Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1374303) (merged b6d073da into 58b92453).

---------------------------------------------------------------------------

by travisbot at 2012-05-19T13:28:18Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1374568) (merged fd144c96 into 58b92453).

---------------------------------------------------------------------------

by travisbot at 2012-05-19T13:35:38Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1374609) (merged 89a8d851 into 58b92453).

---------------------------------------------------------------------------

by travisbot at 2012-05-21T04:31:46Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1385764) (merged 0d5b8322 into 58b92453).

---------------------------------------------------------------------------

by travisbot at 2012-05-21T07:21:56Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1386545) (merged 3e1d3b8 into 1407f112).

---------------------------------------------------------------------------

by stof at 2012-06-09T13:24:14Z

seems good
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants