Fixed cleaning up after installation
authorTim Düsterhus <timwolla@arcor.de>
Sun, 28 Aug 2011 15:03:37 +0000 (17:03 +0200)
committerTim Düsterhus <timwolla@arcor.de>
Sun, 28 Aug 2011 15:05:12 +0000 (17:05 +0200)
wcfsetup/install/files/lib/system/WCFSetup.class.php
wcfsetup/install/files/lib/util/DirectoryUtil.class.php

index 50cc72ec2eba1bd293ab9d5939285d88d7d2fc75..8da8164379a008a34d220508083e086b3b21030d 100644 (file)
@@ -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);
        }
        
        /**
index bcda8809ec85ede78ba26ceff59ac22ebcaa24e0..6bc10f1cd7e05eb6034827026323962c1caf14b0 100644 (file)
@@ -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);