From: Tim Düsterhus Date: Fri, 20 May 2022 09:30:12 +0000 (+0200) Subject: Clean all directories that match the tmp naming pattern at the end of WCFSetup X-Git-Tag: 6.0.0_Alpha_1~1267^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=00df4141f0d246a4c7e8f69055b27d2561577b06;p=GitHub%2FWoltLab%2FWCF.git Clean all directories that match the tmp naming pattern at the end of WCFSetup Since e41dfd007b12baed65ab7679fb679e53bcd2adf5 the temporary directory for WCFSetup resides in the webroot instead of some system internal temporary directory. As such temporary files might remain in the webroot and likely will never be cleaned if the install.php is accessed multiple times before the setup is completed. Fix this by deleting all directories that match the pattern for the name of the temporary directory once the setup is completed successfully. --- diff --git a/wcfsetup/install.php b/wcfsetup/install.php index cefb88a047..9cdd3802ae 100644 --- a/wcfsetup/install.php +++ b/wcfsetup/install.php @@ -619,7 +619,7 @@ class BasicFileUtil { * Returns the temp folder for the installation. */ public static function getInstallTempFolder(): string { - $dir = __DIR__ . '/WCFSetup-' . TMP_FILE_PREFIX . '/'; + $dir = INSTALL_SCRIPT_DIR . '/WCFSetup-' . TMP_FILE_PREFIX . '/'; @mkdir($dir); self::makeWritable($dir); diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index 40819562af..28915e0f92 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -1317,21 +1317,33 @@ final class WCFSetup extends WCF SessionHandler::getInstance()->update(); // Delete tmp files - $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator( - TMP_DIR . '/', - \RecursiveDirectoryIterator::CURRENT_AS_FILEINFO | \RecursiveDirectoryIterator::SKIP_DOTS - ), - \RecursiveIteratorIterator::CHILD_FIRST - ); - foreach ($iterator as $path) { - if ($path->isDir()) { - \rmdir($path); - } else { - \unlink($path); + foreach (new \DirectoryIterator(\INSTALL_SCRIPT_DIR) as $fileInfo) { + if (!$fileInfo->isDir()) { + continue; + } + + if (!\preg_match('/^WCFSetup-[0-9a-f]{16}$/', $fileInfo->getBasename())) { + continue; + } + + $tmpDirectory = $fileInfo->getPathname(); + + $tmpDirectoryIterator = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator( + $tmpDirectory, + \RecursiveDirectoryIterator::CURRENT_AS_FILEINFO | \RecursiveDirectoryIterator::SKIP_DOTS + ), + \RecursiveIteratorIterator::CHILD_FIRST + ); + foreach ($tmpDirectoryIterator as $tmpFile) { + if ($tmpFile->isDir()) { + \rmdir($tmpFile); + } else { + \unlink($tmpFile); + } } + \rmdir($tmpDirectory); } - \rmdir(TMP_DIR . '/'); return $output; }