Description
Symfony version(s) affected
5.4 >=
Description
The Finder component is not able to traverse folders when the supplied path is a stream (for instance ftp://localhost/
and the current environment is Windows.
Note that I have tested this on 5.4
as my Windows machine has PHP7.4
, I have tests this and the the same bug appears for PHP8.2
and the current latest Finder version 7.2
.
How to reproduce
Setup an ftp server, for instance garethflowers/docker-ftp-server
with the servers root pointing at a directory with some of directories and files more than 1 level deep.
On Windows try the following code:
use Symfony\Component\Finder\Finder;
require __DIR__.'/vendor/autoload.php';
$finder = new Finder();
foreach ($finder->in("ftp://user:123@my-ftp-server/") as $file) {
print_r($file);
}
Note that only the first level is displayed.
Then try:
use Symfony\Component\Finder\Finder;
require __DIR__.'/vendor/autoload.php';
$finder = new Finder();
foreach ($finder->in("ftp://user:123@my-ftp-server/") as $file) {
dump($file->getMTime());
}
Note that PHP throws fatal error, although this is now fixed since 57895. Still though, only the first level is displayed.
Possible Solution
Possible allowing the RecursiveDirectoryIterator::UNIX_PATHS
flag to be enabled, optionally, similar to RecursiveDirectoryIterator::FOLLOW_SYMLINKS
in Finder::searchInDirectory
when it is building its iterators.
$flags |= \RecursiveDirectoryIterator::UNIX_PATHS;
This seems to "fix" the problem for me and seems to work well on Linux and Windows. There maybe further unseen pitfalls though!
Additional Context
No response