[BUGFIX] Avoid fatal when flushed directory is a symlink 74/59374/3
authorHelmut Hummel <typo3@helhum.io>
Tue, 8 Jan 2019 14:33:08 +0000 (15:33 +0100)
committerMathias Brodala <mbrodala@pagemachine.de>
Wed, 9 Jan 2019 15:28:19 +0000 (16:28 +0100)
\TYPO3\CMS\Core\Utility\GeneralUtility::flushDirectory tries to
rename the given directory to be able to atomically flush the
contents of the directory. This however fails, when the given
folder is a symlink.

We now catch this case by checking whether the given directory
is a symlink and resolve it with realpath.

While this does not cover all possible cases, it improves the
case where the folder containing the symlink is also writable.

Resolves: #87367
Releases: master, 9.5, 8.7
Change-Id: Ic812a5eaa86cca4d81aee31b4a3fbdce052994a0
Reviewed-on: https://review.typo3.org/59374
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Fabien Udriot <fabien.udriot@ecodev.ch>
Tested-by: Fabien Udriot <fabien.udriot@ecodev.ch>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: Mathias Brodala <mbrodala@pagemachine.de>
typo3/sysext/core/Classes/Utility/GeneralUtility.php

index 50102cd..004ffc1 100644 (file)
@@ -2164,8 +2164,13 @@ class GeneralUtility
     {
         $result = false;
 
+        if (is_link($directory)) {
+            // Avoid attempting to rename the symlink see #87367
+            $directory = realpath($directory);
+        }
+
         if (is_dir($directory)) {
-            $temporaryDirectory = rtrim($directory, '/') . '.' . StringUtility::getUniqueId('remove') . '/';
+            $temporaryDirectory = rtrim($directory, '/') . '.' . StringUtility::getUniqueId('remove');
             if (rename($directory, $temporaryDirectory)) {
                 if ($flushOpcodeCache) {
                     self::makeInstance(OpcodeCacheService::class)->clearAllActive($directory);