From 364a2e49de8a13606bf295280f7a77ac569947ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 28 Aug 2011 17:03:37 +0200 Subject: [PATCH] Fixed cleaning up after installation --- .../install/files/lib/system/WCFSetup.class.php | 13 +++---------- .../install/files/lib/util/DirectoryUtil.class.php | 9 +++++---- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index 50cc72ec2e..8da8164379 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -16,6 +16,7 @@ use wcf\system\session\SessionHandler; use wcf\system\setup\Installer; use wcf\system\template\SetupTemplateEngine; use wcf\system\WCF; +use wcf\util\DirectoryUtil; use wcf\util\FileUtil; use wcf\util\StringUtil; use wcf\util\UserUtil; @@ -1068,16 +1069,8 @@ class WCFSetup extends WCF { WCF::getTPL()->display('stepInstallPackages'); // delete tmp files - $directory = TMP_DIR.TMP_FILE_PREFIX.'/'; - $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)); - while ($it->valid()) { - // delete all files except directories and packages (required for post-wcfsetup installation) - if (!$it->isDot() && !$it->isDir() && !preg_match('~\.tar(\.gz)?$~', $it->getSubPathName())) { - @unlink($it->key()); - } - - $it->next(); - } + $directory = TMP_DIR.'/'; + DirectoryUtil::getInstance($directory)->removePattern('~\.tar(\.gz)?$~', true); } /** diff --git a/wcfsetup/install/files/lib/util/DirectoryUtil.class.php b/wcfsetup/install/files/lib/util/DirectoryUtil.class.php index bcda8809ec..6bc10f1cd7 100644 --- a/wcfsetup/install/files/lib/util/DirectoryUtil.class.php +++ b/wcfsetup/install/files/lib/util/DirectoryUtil.class.php @@ -282,12 +282,13 @@ class DirectoryUtil { /** * Removes all files that match the given pattern. * - * @param string $pattern pattern to match + * @param string $pattern pattern to match + * @param boolean $negativeMatch should the pattern be inversed */ - public function removePattern($pattern) { + public function removePattern($pattern, $negativeMatch = false) { if (!$this->recursive) throw new SystemException('Removing of files only works in recursive mode'); - $files = $this->getFileObjects(self::SORT_NONE, $pattern); + $files = $this->getFileObjects(self::SORT_NONE, $pattern, $negativeMatch); foreach ($files as $filename => $obj) { if (!is_writable($obj->getPath())) { @@ -295,7 +296,7 @@ class DirectoryUtil { } if ($obj->isDir()) { - rmdir($filename); + @rmdir($filename); } else if ($obj->isFile()) { unlink($filename); -- 2.20.1