php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62433 Inconsistent behavior of RecursiveDirectoryIterator to dot files (. and ..)
Submitted: 2012-06-27 17:59 UTC Modified: 2012-07-02 03:34 UTC
From: miau dot jp at gmail dot com Assigned: laruence (profile)
Status: Closed Package: SPL related
PHP Version: 5.4.4 OS: All
Private report: No CVE-ID: None
 [2012-06-27 17:59 UTC] miau dot jp at gmail dot com
Description:
------------
RecurisveDirectoryIterator skips dot files (. and ..) that appear on
the top of directory entries only. Since some file systems (e.g.: ext3, FAT32)
doesn't sort directory entries, the behavior of RecursiveDirectoryIterator
is inconsistent.

RecursiveDirectoryIterator should either always skip dot files, or never
skip dot files. Otherwise many developer mistakenly assume that 
RecurisveDirectoryIterator always skips dot files, and add a bug to their
programs.

----

(tested on ext3 file system)

# mkdir test
# cd test
# cat <<\EOF >test.php
<?php
echo __DIR__ . "\n";
print_r(array_keys(iterator_to_array(
    new RecursiveDirectoryIterator(__DIR__)
)));
EOF

(use "-U" option not to sort)
# ls -liaU
total 16
8314945 drwxr-x--- 8 root root 4096  6月 28 02:15 ..
8315727 drwxr-xr-x 2 root root 4096  6月 28 02:16 .
8315728 -rw-r--r-- 1 root root  114  6月 28 02:16 test.php
# php test.php
/root/test
Array
(
    [0] => /root/test/test.php
)

# touch 1 2 3 4 5
# ls -liaU
total 16
8315730 -rw-r--r-- 1 root root    0  6月 28 02:16 2
8315733 -rw-r--r-- 1 root root    0  6月 28 02:16 5
8314945 drwxr-x--- 8 root root 4096  6月 28 02:15 ..
8315727 drwxr-xr-x 2 root root 4096  6月 28 02:16 .
8315728 -rw-r--r-- 1 root root  114  6月 28 02:16 test.php
8315729 -rw-r--r-- 1 root root    0  6月 28 02:16 1
8315731 -rw-r--r-- 1 root root    0  6月 28 02:16 3
8315732 -rw-r--r-- 1 root root    0  6月 28 02:16 4
# php test.php
/root/test
Array
(
    [0] => /root/test/2
    [1] => /root/test/5
    [2] => /root/test/..
    [3] => /root/test/.
    [4] => /root/test/test.php
    [5] => /root/test/1
    [6] => /root/test/3
    [7] => /root/test/4
)

(To ensure skippping dot files, construct the RecursiveDirectoryIterator
with SKIP_DOTS flag for now.)

# cat <<\EOF >test.php
<?php
echo __DIR__ . "\n";
print_r(array_keys(iterator_to_array(
    new RecursiveDirectoryIterator(__DIR__, FilesystemIterator::SKIP_DOTS)
)));
EOF
# php test.php
/root/test
Array
(
    [0] => /root/test/2
    [1] => /root/test/5
    [2] => /root/test/test.php
    [3] => /root/test/1
    [4] => /root/test/3
    [5] => /root/test/4
)



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-02 03:33 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=be4053cea0462c9de5396641f4e4fa2f56f5a675
Log: Fixed bug #62433 (Inconsistent behavior of RecursiveDirectoryIterator to dot files).
 [2012-07-02 03:34 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=be4053cea0462c9de5396641f4e4fa2f56f5a675
Log: Fixed bug #62433 (Inconsistent behavior of RecursiveDirectoryIterator to dot files).
 [2012-07-02 03:34 UTC] laruence@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: laruence
 [2012-07-02 03:34 UTC] laruence@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-07-09 10:46 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2032470e4113dfbf04a1ed3b12de85ffcde6f367
Log: fixed #62433 test for win
 [2014-10-07 23:23 UTC] stas@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=2032470e4113dfbf04a1ed3b12de85ffcde6f367
Log: fixed #62433 test for win
 [2014-10-07 23:24 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=be4053cea0462c9de5396641f4e4fa2f56f5a675
Log: Fixed bug #62433 (Inconsistent behavior of RecursiveDirectoryIterator to dot files).
 [2014-10-07 23:34 UTC] stas@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=2032470e4113dfbf04a1ed3b12de85ffcde6f367
Log: fixed #62433 test for win
 [2014-10-07 23:34 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=be4053cea0462c9de5396641f4e4fa2f56f5a675
Log: Fixed bug #62433 (Inconsistent behavior of RecursiveDirectoryIterator to dot files).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 11:01:29 2024 UTC