php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75188 RecursiveIteratorIterator::SELF_FIRST not working
Submitted: 2017-09-11 13:07 UTC Modified: 2018-10-18 12:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: candeliere at trendengineering dot it Assigned:
Status: Open Package: SPL related
PHP Version: 7.1.9 OS: Linux
Private report: No CVE-ID: None
 [2017-09-11 13:07 UTC] candeliere at trendengineering dot it
Description:
------------
According to the (hard to find) documentation, SELF_FIRST should output "branches" first, then "leaves" (in case of RecursiveDirectoryIterator, it should output folders first, then files) but it is not doing that. Apparently it returns the folder structure as the underlying filesystem is returning it untouched.
NOTE: Please understand that I'm not talking about *alphabetical* order. This is related to the fact that the test script below will generate an error ("no such file or directory)
Actually the first iteration will try to copy /<my/custom/path>/themes/SimpleSoloEmailVideo/content.php, but /<my/custom/path>/themes/SimpleSoloEmailVideo/ doesn't exist yet.
The test code would work perfectly if the SELF_FIRST order is guaranteed.
 

Test script:
---------------
    function copy_recursive($source, $dest)
    {
        if (is_dir($source)) {
            $iterator = new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
                RecursiveIteratorIterator::SELF_FIRST
            );
            foreach ($iterator as $file) {
                if ($file->isDir()) {
                    mkdir($dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName(), 0777, true);
                } else {
                    copy($file, $dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName());
                }
                error_log($file); 
            }
        } else {
            copy($source, $dest);
        }
    }


Expected result:
----------------
/<my/custom/path>/themes/SimpleSoloEmailVideo/css/
/<my/custom/path>/themes/SimpleSoloEmailVideo/css/style.css
/<my/custom/path>/themes/SimpleSoloEmailVideo/js/
/<my/custom/path>/themes/SimpleSoloEmailVideo/js/mycoolscript.js
/<my/custom/path>/themes/SimpleSoloEmailVideo/_imgs/
/<my/custom/path>/themes/SimpleSoloEmailVideo/content.php
/<my/custom/path>/themes/SimpleSoloEmailVideo/snapshot.png
/<my/custom/path>/themes/SimpleSoloEmailVideo/_hotarea_sample.php
/<my/custom/path>/themes/SimpleSoloEmailVideo/theme.xml
/<my/custom/path>/themes/SimpleSoloEmailVideo/thumb-65x65.png


Actual result:
--------------
/<my/custom/path>/themes/SimpleSoloEmailVideo/content.php
/<my/custom/path>/themes/SimpleSoloEmailVideo/snapshot.png
/<my/custom/path>/themes/SimpleSoloEmailVideo/css
/<my/custom/path>/themes/SimpleSoloEmailVideo/css/style.css
/<my/custom/path>/themes/SimpleSoloEmailVideo/js
/<my/custom/path>/themes/SimpleSoloEmailVideo/js/mycoolscript.js
/<my/custom/path>/themes/SimpleSoloEmailVideo/_hotarea_sample.php
/<my/custom/path>/themes/SimpleSoloEmailVideo/theme.xml
/<my/custom/path>/themes/SimpleSoloEmailVideo/_imgs
/<my/custom/path>/themes/SimpleSoloEmailVideo/thumb-65x65.png


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-18 12:22 UTC] cmb@php.net
-Package: SPL_Types +Package: SPL related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 08:01:28 2024 UTC