8000 [Finder] BC: Manuelly added files are missing · Issue #40022 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Finder] BC: Manuelly added files are missing #40022

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
shyim opened this issue Jan 28, 2021 · 4 comments
Closed

[Finder] BC: Manuelly added files are missing #40022

shyim opened this issue Jan 28, 2021 · 4 comments

Comments

@shyim
Copy link
Contributor
shyim commented Jan 28, 2021

Symfony version(s) affected: 4.4.19

Description
Finder lists only one manuelly added file

How to reproduce

$finder = new Finder();
        $finder
            ->sortByName()
            ->files()
            ->followLinks()
            ->name('*.php');

        $finder->append([__DIR__ . '/Context.php']);
        $finder->append([__DIR__ . '/Logger.phpp']);
        $finder->append([__DIR__ . '/Serializer.php']);

        foreach ($finder as $item) {
            var_dump($item->getPathname());
        }

Output: v4.4.19:
string(59) "/var/www/html/vendor/zircote/swagger-php/src/Serializer.php"

Output: v4.4.18
string(56) "/var/www/html/vendor/zircote/swagger-php/src/Context.php"
string(56) "/var/www/html/vendor/zircote/swagger-php/src/Logger.phpp"
string(59) "/var/www/html/vendor/zircote/swagger-php/src/Serializer.php"

Possible Solution
Revert symfony/finder@94a9b86

Additional context

@stof
Copy link
Member
stof commented Jan 28, 2021

your reproducer is likely incomplete as $directory is not defined in it

8000

@shyim
Copy link
Contributor Author
shyim commented Jan 28, 2021

Ahh That line is not needed sorry :) Just point to some files. And you will get only one

@stof
Copy link
Member
stof commented Jan 28, 2021

I think I understood the issue. SortableIterator uses iterator_to_array($iterator, preserve_keys: true). The effect of that is that it removes duplicate keys in the iterator (as arrays don't support duplicate keys).

This is not really an issue for cases providing a directory, because the full path is used as keys in such iterators. But when using ->append() with an array, the Finder component will uses incremented keys for that array only, and so using append multiple times will generate duplicate keys in the final iterator. The Finder should probably also build iterators using the path as key for such case instead of using integers.

@xabbuh
Copy link
Member
xabbuh commented Jan 28, 2021

see #40023

nicolas-grekas added a commit that referenced this issue Jan 28, 2021
…xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Finder]  use proper keys to not override appended files

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #40022
| License       | MIT
| Doc PR        |

Commits
-------

036c8d7 use proper keys to not override appended files
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

5 participants
0