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: -
From: candeliere at trendengineering dot it Assigned:
Status: Open Package: SPL_Types (PECL)
PHP Version: 7.1.9 OS: Linux
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC