[BUGFIX] Avoid race conditions in typo3temp/Cache 95/39895/7
authorBernhard Kraft <kraft@webconsulting.at>
Tue, 2 Jun 2015 13:19:23 +0000 (15:19 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Thu, 25 Jun 2015 15:37:40 +0000 (17:37 +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/39895
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
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 f24df41..d8b019a 100755 (executable)
@@ -2810,14 +2810,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 bool 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 7297b5e..f7c480e 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();