[BUGFIX] FAL: Correctly iterate folder content with offset 75/52275/2
authorMarkus Klein <markus.klein@typo3.org>
Thu, 30 Mar 2017 22:06:58 +0000 (00:06 +0200)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Fri, 31 Mar 2017 10:18:31 +0000 (12:18 +0200)
Whenever a list of files of a folder is queried with an offset
make sure we handle filtered files correctly by not taking them
into account when searching for the first eligible file for the
result.

A direct seek() to the start position is wrong as those first files
may contain files would be later on filtered.
The solution is to iterate the whole file list and only count
non-filtered elements to reach the correct starting point.

Releases: master, 7.6, 6.2
Resolves: #80589
Change-Id: I79a6d298599d31aa49c36fd51cc5bbe2cf2ccf3a
Reviewed-on: https://review.typo3.org/52275
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Riccardo De Contardi <erredeco@gmail.com>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php

index edf21de..4836de5 100644 (file)
@@ -354,7 +354,6 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
         if ($iterator->count() === 0) {
             return [];
         }
-        $iterator->seek($start);
 
         // $c is the counter for how many items we still have to fetch (-1 is unlimited)
         $c = $numberOfItems > 0 ? $numberOfItems : - 1;
@@ -376,12 +375,15 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
                 ) {
                     continue;
                 }
-
-                $items[$iteratorItem['identifier']] = $iteratorItem['identifier'];
-                // Decrement item counter to make sure we only return $numberOfItems
-                // we cannot do this earlier in the method (unlike moving the iterator forward) because we only add the
-                // item here
-                --$c;
+                if ($start > 0) {
+                    $start--;
+                } else {
+                    $items[$iteratorItem['identifier']] = $iteratorItem['identifier'];
+                    // Decrement item counter to make sure we only return $numberOfItems
+                    // we cannot do this earlier in the method (unlike moving the iterator forward) because we only add the
+                    // item here
+                    --$c;
+                }
             } catch (Exception\InvalidPathException $e) {
             }
         }