[BUGFIX] Avoid race conditions in typo3temp/Cache 50/40650/2
authorBernhard Kraft <kraft@webconsulting.at>
Thu, 25 Jun 2015 15:41:44 +0000 (17:41 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Thu, 25 Jun 2015 15:46:45 +0000 (17:46 +0200)
Race conditions can occur when the cache in typo3temp/Cache gets
cleared, for example by using the Install Tool "Clear all caches"
button. The cache is currently cleared using GeneralUtility::rmdir()
which does a directory traversal and unlinks all contained files.
Instead GeneralUtility::flushDirectory() should get used. This method
renames the directory into a temp-dir name and then removes the temp-dir
using GeneralUtility:rmdir().

Change-Id: I23f31da4e7b1730edee9007e713a51d4b39c6f1c
Resolves: #67238
Releases: master, 6.2
Reviewed-on: http://review.typo3.org/40650
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/install/Classes/Service/ClearCacheService.php

index 4062bdb..8115e70 100755 (executable)
@@ -2933,14 +2933,16 @@ Connection: close
         *
         * @param string $directory The directory to be renamed and flushed
         * @param bool $keepOriginalDirectory Whether to only empty the directory and not remove it
+        * @param bool $flushOpcodeCache Also flush the opcode cache right after renaming the directory.
         * @return boolean Whether the action was successful
         */
-       static public function flushDirectory($directory, $keepOriginalDirectory = FALSE) {
+       static public function flushDirectory($directory, $keepOriginalDirectory = FALSE, $flushOpcodeCache = FALSE) {
                $result = FALSE;
 
                if (is_dir($directory)) {
                        $temporaryDirectory = rtrim($directory, '/') . '.' . uniqid('remove', TRUE) . '/';
                        if (rename($directory, $temporaryDirectory)) {
+                               $flushOpcodeCache && OpcodeCacheUtility::clearAllActive($directory);
                                if ($keepOriginalDirectory) {
                                        self::mkdir($directory);
                                }
index a667b07..018999c 100644 (file)
@@ -45,7 +45,7 @@ class ClearCacheService {
         */
        public function clearAll() {
                // Delete typo3temp/Cache
-               GeneralUtility::rmdir(PATH_site . 'typo3temp/Cache', TRUE);
+               GeneralUtility::flushDirectory(PATH_site . 'typo3temp/Cache', TRUE, TRUE);
 
                $bootstrap = \TYPO3\CMS\Core\Core\Bootstrap::getInstance();
                $bootstrap->unregisterClassLoader();