Browse Source

Fix file cache engine trying to clear root on realpath failure.

When `getRealPath()` fails and returns `false`, the path will finally
contain only the appended directory separator, thus pointing to the root
directory.
ndm2 5 years ago
parent
commit
9c8cd8ccbd
1 changed files with 9 additions and 3 deletions
  1. 9 3
      src/Cache/Engine/FileEngine.php

+ 9 - 3
src/Cache/Engine/FileEngine.php

@@ -277,12 +277,18 @@ class FileEngine extends CacheEngine
             RecursiveIteratorIterator::SELF_FIRST
         );
         $cleared = [];
-        foreach ($contents as $path) {
-            if ($path->isFile()) {
+        /** @var \SplFileInfo $fileInfo */
+        foreach ($contents as $fileInfo) {
+            if ($fileInfo->isFile()) {
                 continue;
             }
 
-            $path = $path->getRealPath() . DIRECTORY_SEPARATOR;
+            $realPath = $fileInfo->getRealPath();
+            if (!$realPath) {
+                continue;
+            }
+
+            $path = $realPath . DIRECTORY_SEPARATOR;
             if (!in_array($path, $cleared, true)) {
                 $this->_clearDirectory($path, $now, $threshold);
                 $cleared[] = $path;