[BUGFIX] Warning when clearing all caches from within install tool 89/43289/4
authorBernhard Kraft <kraft@webconsulting.at>
Mon, 14 Sep 2015 09:01:43 +0000 (11:01 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Mon, 4 Apr 2016 13:08:48 +0000 (15:08 +0200)
When using the "clearAllCache" button a warning message gets shown
(or eventually just logged) when the APC file cache is used.

Reason is that the method "OpcodeCacheUtility::clearAllActive()"
will not allow to clear whole directories. Per definition the used
method "apc_delete_file()" allows only to delete single file-cache
entries from the APC cache when called with a string argument.

So for this to work the method "apc_delete_file()" got changed to
use the "ApcIterator" class using a regular expression matching
the given directory.

Change-Id: I7148fb3c176e05518901b032eccddfa2dd448c4a
Resolves: #69773
Releases: 6.2
Reviewed-on: https://review.typo3.org/43289
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Classes/Utility/OpcodeCacheUtility.php

index a5f7f87..26572ee 100755 (executable)
@@ -2955,10 +2955,10 @@ Connection: close
                if (is_dir($directory)) {
                        $temporaryDirectory = rtrim($directory, '/') . '.' . uniqid('remove', TRUE) . '/';
                        if (rename($directory, $temporaryDirectory)) {
-                               $flushOpcodeCache && OpcodeCacheUtility::clearAllActive($directory);
                                if ($keepOriginalDirectory) {
                                        self::mkdir($directory);
                                }
+                               $flushOpcodeCache && OpcodeCacheUtility::clearAllActive($directory);
                                clearstatcache();
                                $result = self::rmdir($temporaryDirectory, TRUE);
                        }
index 344b3a9..a097577 100644 (file)
@@ -78,11 +78,17 @@ class OpcodeCacheUtility {
                                'error' => $apcVersion && VersionNumberUtility::convertVersionNumberToInteger($apcVersion) < 3001007,
                                'clearCallback' => function ($fileAbsPath) {
                                        if ($fileAbsPath !== NULL && OpcodeCacheUtility::getCanInvalidate('APC')) {
-                                               // This may output a warning like: PHP Warning: apc_delete_file(): Could not stat file
-                                               // This warning isn't true, this means that apc was unable to generate the cache key
-                                               // which depends on the configuration of APC.
-                                               apc_delete_file($fileAbsPath);
+                                               if (is_dir($fileAbsPath)) {
+                                                       // APC can't flush whole directories directly by just givin' the directory path.
+                                                       // Instead retrieve all matching cache entries using an ApcIterator.
+                                                       $quotedPath = preg_quote(rtrim($fileAbsPath, '/') . '/', '/');
+                                                       $iterator = new \APCIterator('file', '/^'. $quotedPath . '.*/');
+                                                       apc_delete_file($iterator);
+                                               } else {
+                                                       apc_delete_file($fileAbsPath);
+                                               }
                                        } else {
+                                               // Clear whole cache at once.
                                                apc_clear_cache('opcode');
                                        }
                                }