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

RecursiveDirectoryIterator regression wrt. junctions #9674

Open
LHavlicek opened this issue Oct 5, 2022 · 3 comments · May be fixed by #9774
Open

RecursiveDirectoryIterator regression wrt. junctions #9674

LHavlicek opened this issue Oct 5, 2022 · 3 comments · May be fixed by #9774

Comments

@LHavlicek
Copy link

Description

When loading files in $path using

<?php
$directory = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::FOLLOW_SYMLINKS);
$iterator = new RecursiveIteratorIterator($directory);
?>

PHP 8.1 on Windows (Windows 10) does not include files located in a folder that is a symlink (junction).

The unread folder is on the same disk and its symlink (junction) is inserted into $path.

If I view $directory using

<?php
foreach ($directory as $i) {
    var_dump($i);
}
?>

I can see the symlinked folders. But if I try to load the files using

<?php
foreach ($iterator as $i) {
    var_dump($i);
}
?>

the files located in the symlinked folder are no longer dumped. The files in the actual folders in $path are included.

In PHP 8.0 and below, everything is fine and the above code works.

Sorry for my English.

PHP Version

PHP 8.1.11

Operating System

Windows 10

@cmb69
Copy link
Member

cmb69 commented Oct 5, 2022

Thanks for reporting! The regression has been introduced by commit f323baa, where the change to RecursiveDirectoryIterator::hasChildren() apparently is not prepared to handle kind of hard-linked directories. I'll have a closer look.

@cmb69
Copy link
Member

cmb69 commented Oct 18, 2022

a folder that is a symlink (junction).

Junctions are not symlinks; they are more like hardlinks, but still different. If you want to create symlinked folders on Windows, use mklink /d. If the folders were symlinked, your script worked as intended; on junctions are broken as of PHP 8.1.0.

@cmb69 cmb69 changed the title RecursiveDirectoryIterator with RecursiveIteratorIterator does not include symlinked folders on windows in PHP 8.1 RecursiveDirectoryIterator regression wrt. junctions Oct 18, 2022
cmb69 added a commit to cmb69/php-src that referenced this issue Oct 18, 2022
If we `lstat()` a junction on Windows, it is not `S_ISLNK()`, but we
still must not assume that it is not a link (in the broadest sense).
In lack of a proper way to detect that, we use the fact that `.st_mode`
is zero in this case.
@angelcoding
Copy link

Hi. This bug has been causing me some headaches recently because composer only uses junctions on Windows for path based repositories and I have a third party CMS that uses RecursiveDirectoryIterator to scan those directories (without success).

Not sure if this is usual for PHP, but the above fix was added a year ago and nothing has happened since.
Is that fix likely to make it through soon?

Many thanks!

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

Successfully merging a pull request may close this issue.

3 participants