[BUGFIX] FAL wrong \RecursiveIteratorIterator usage 02/22602/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Fri, 26 Jul 2013 18:54:23 +0000 (20:54 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 26 Jul 2013 19:20:49 +0000 (21:20 +0200)
If using \RecursiveIteratorIterator on \RecursiveDirectoryIterator,
flag SELF_FIRST must be used, otherwise only leaves (files) and not
also directories are returned. This behavior is a bit dependent on
the PHP version used, younger versions (> 5.3.3 seem to do it
correctly).

Furthermore, in copyFolderWithinStorage() $itemSubPath contains
the "relative" path part and not only the node name, checking
equality to "." or ".." fails then if handling sub directories.
So, directories may be created multiple times, resulting in mkdir()
warnings. This is fixed by getting the node name itself and using
that for comparison.

Resolves: #50476
Releases: 6.2, 6.1, 6.0

Change-Id: Ifac4b28f4e02ec8a9bf5891739cf66c1e1074af9
Reviewed-on: https://review.typo3.org/22602
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php

index a6db44b..e5eb48d 100644 (file)
@@ -431,7 +431,7 @@ class LocalDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
         */
        protected function getFileAndFoldernamesInPath($path, $recursive = FALSE) {
                if ($recursive) {
-                       $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::CURRENT_AS_FILEINFO));
+                       $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::CURRENT_AS_FILEINFO), \RecursiveIteratorIterator::SELF_FIRST);
                } else {
                        $iterator = new \RecursiveDirectoryIterator($path, \FilesystemIterator::CURRENT_AS_FILEINFO);
                }
@@ -891,13 +891,17 @@ class LocalDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
                while ($iterator->valid()) {
                        /** @var $current \RecursiveDirectoryIterator */
                        $current = $iterator->current();
+                       $fileName = $current->getFilename();
                        $itemSubPath = $iterator->getSubPathname();
-                       if ($current->isDir() && !($itemSubPath === '..' || $itemSubPath === '.')) {
+                       if ($current->isDir() && !($fileName === '..' || $fileName === '.')) {
                                mkdir($targetFolderPath . $itemSubPath);
                        } elseif ($current->isFile()) {
                                $result = copy($sourceFolderPath . $itemSubPath, $targetFolderPath . $itemSubPath);
                                if ($result === FALSE) {
-                                       throw new \TYPO3\CMS\Core\Resource\Exception\FileOperationErrorException('Copying file "' . $sourceFolderPath . $itemSubPath . '" to "' . $targetFolderPath . $itemSubPath . '" failed.', 1330119452);
+                                       throw new \TYPO3\CMS\Core\Resource\Exception\FileOperationErrorException(
+                                               'Copying file "' . $sourceFolderPath . $itemSubPath . '" to "' . $targetFolderPath . $itemSubPath . '" failed.',
+                                               1330119452
+                                       );
                                }
                        }
                        $iterator->next();