Skip to content
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

[Finder] File listing broken on non Filesystem (ftp in my case) due to 2.8.3 changes #18013

Closed
smurfy opened this issue Mar 4, 2016 · 7 comments

Comments

@smurfy
Copy link

smurfy commented Mar 4, 2016

The commit cba206a removes the RecursiveDirectoryIterator check and only does the FilesystemIterator check in FilterIterator in the rewind method

This breaks file listing on ftp connections and probably all non Filesystem listings.

-            if ($innerIterator instanceof RecursiveDirectoryIterator) {
-                if ($innerIterator->isRewindable()) {
-                    $innerIterator->next();
-                    $innerIterator->rewind();
-                }
-            } elseif ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
-                $iterator->getInnerIterator()->next();
-                $iterator->getInnerIterator()->rewind();
+            if ($innerIterator instanceof \FilesystemIterator) {
+                $innerIterator->next();
+                $innerIterator->rewind();

Solution would be revert this part of the commit.

@mogoman
Copy link

mogoman commented Mar 4, 2016

+1 for example this breaks the following:

$finder = new Finder();
$finder->depth(0);
foreach ($finder->sortByName()->in('ftp://user@localhost/') as $file) {
    // ...
}

@xabbuh
Copy link
Member

xabbuh commented Mar 7, 2016

What error do you get now?

@smurfy
Copy link
Author

smurfy commented Mar 7, 2016

What error do you get now?

not sure what you mean. Currently you won't get an error/exception, but you also get no listing of ftp remote streams.

@mogoman
Copy link

mogoman commented Mar 7, 2016

Full example:

Output using FTP client lists 2 files and 2 directories

ftp> ls -l
229 Entering Extended Passive Mode (|||26208|)
150 Opening ASCII mode data connection for file list
-rw-rw-r--   1 xxx   xxx          0 Oct  9 09:48 a dir with space
drwxrwxr-x   2 xxx   xxx          6 Oct  9 09:48 a real dir with space
drwxrwxr-x   2 xxx   xxx          6 Oct  9 08:14 bar_is_a_directory
-rw-rw-r--   1 xxx   xxx  634355712 Oct  9 08:40 foo.txt
226 Transfer complete

Finder in SF 2.8.3 connecting to the FTP server and doing a file listing lists only the first directory

foreach ($finder->sortByName()->in($dir) as $file) {
    print_r($file);

Output

    Symfony\Component\Finder\SplFileInfo Object
    (
        [relativePath:Symfony\Component\Finder\SplFileInfo:private] =>
        [relativePathname:Symfony\Component\Finder\SplFileInfo:private] => a real dir with space
        [pathName:SplFileInfo:private] => ftp://xxx:yyy@localhost:21//a real dir with space
        [fileName:SplFileInfo:private] => a real dir with space
    )

Finder in SF 2.8.2 connecting to the FTP server and doing a file listing lists everything correctly

Symfony\Component\Finder\SplFileInfo Object
(
    [relativePath:Symfony\Component\Finder\SplFileInfo:private] => 
    [relativePathname:Symfony\Component\Finder\SplFileInfo:private] => a real dir with space
    [pathName:SplFileInfo:private] => ftp://xxx:yyy@localhost:21//a real dir with space
    [fileName:SplFileInfo:private] => a real dir with space
)
Symfony\Component\Finder\SplFileInfo Object
(
    [relativePath:Symfony\Component\Finder\SplFileInfo:private] => 
    [relativePathname:Symfony\Component\Finder\SplFileInfo:private] => a dir with space
    [pathName:SplFileInfo:private] => ftp://xxx:yyy@localhost:21//a dir with space
    [fileName:SplFileInfo:private] => a dir with space
)
Symfony\Component\Finder\SplFileInfo Object
(
    [relativePath:Symfony\Component\Finder\SplFileInfo:private] => 
    [relativePathname:Symfony\Component\Finder\SplFileInfo:private] => foo.txt
    [pathName:SplFileInfo:private] => ftp://xxx:yyy@localhost:21//foo.txt
    [fileName:SplFileInfo:private] => foo.txt
)
Symfony\Component\Finder\SplFileInfo Object
(
    [relativePath:Symfony\Component\Finder\SplFileInfo:private] => 
    [relativePathname:Symfony\Component\Finder\SplFileInfo:private] => bar_is_a_directory
    [pathName:SplFileInfo:private] => ftp://xxx:yyy@localhost:21//bar_is_a_directory
    [fileName:SplFileInfo:private] => bar_is_a_directory
)

As you can see in SF 2.8.3 the Finder doesn't find everything...

@smurfy
Copy link
Author

smurfy commented Mar 7, 2016

I created a gist (https://gist.github.com/smurfy/42490192431342614797) to reproduce.

Breaks on php 5.4.16 (cent os) and php 5.5.9 (ubuntu)
Does not break on 5.5.30 (osx), gets catched by the PHP Version check added by the same commit.

@jakzal
Copy link
Contributor

jakzal commented Mar 8, 2016

@smurfy @mogoman thanks for digging into this

I just tried @smurfy's example and can confirm the behaviour is different depending on PHP version.

status: reviewed

@jakzal
Copy link
Contributor

jakzal commented Mar 8, 2016

Looks like three first files are always excluded (just confirmed this with another ftp). I'll work on a fix.

fabpot added a commit that referenced this issue Mar 9, 2016
This PR was merged into the 2.3 branch.

Discussion
----------

[Finder] Partially revert #17134 to fix a regression

| Q             | A
| ------------- | ---
| Branch        | 2.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18013
| License       | MIT
| Doc PR        | -

Commits
-------

ead1824 [Finder] Partially revert #17134 to fix a regression
@fabpot fabpot closed this as completed Mar 9, 2016
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

7 participants