* Add new function t3lib_div::rmdir() to remove directories recursively
authorMichael Stucki <michael.stucki@typo3.org>
Fri, 27 Apr 2007 22:02:06 +0000 (22:02 +0000)
committerMichael Stucki <michael.stucki@typo3.org>
Fri, 27 Apr 2007 22:02:06 +0000 (22:02 +0000)
* Modify filelist module to make use of the t3lib_div::rmdir()
* Modify internal_clearPageCache() in t3lib_tcemain and make use of t3lib_div::rmdir() as well

git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2277 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
t3lib/class.t3lib_extfilefunc.php
t3lib/class.t3lib_tcemain.php

index 70404a6..695a043 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
 2007-04-27  Michael Stucki  <michael@typo3.org>
 
        * Move type conversion of $TYPO3_CONF_VARS['FE']['pageNotFound_handling']='true' (string) into t3lib/config_default.php
+       * Add new function t3lib_div::rmdir() to remove directories recursively
+       * Modify filelist module to make use of the t3lib_div::rmdir()
+       * Modify internal_clearPageCache() in t3lib_tcemain and make use of t3lib_div::rmdir() as well
 
 2007-04-27  Ingo Renner  <typo3@ingo-renner.com>
 
index 2e0703b..719e518 100755 (executable)
@@ -2551,6 +2551,40 @@ class t3lib_div {
        }
 
        /**
+        * Wrapper function for rmdir, allowing recursive deletion of folders and files
+        *
+        * @param       string          Absolute path to folder, see PHP rmdir() function. Removes trailing slash internally.
+        * @param       boolean         Allow deletion of non-empty directories
+        * @return      boolean         true if @rmdir went well!
+        */
+       function rmdir($path,$removeNonEmpty=false)     {
+               $OK = false;
+               $path = preg_replace('|/$|','',$path);  // Remove trailing slash
+
+               if (file_exists($path)) {
+                       $OK = true;
+
+                       if (is_dir($path))      {
+                               if ($removeNonEmpty==true && $handle = opendir($path))  {
+                                       while ($OK && false !== ($file = readdir($handle)))     {
+                                               if ($file=='.' || $file=='..') continue;
+                                               $OK = t3lib_div::rmdir($path.'/'.$file,$removeNonEmpty);
+                                       }
+                                       closedir($handle);
+                               }
+                               if ($OK)        { $OK = rmdir($path); }
+
+                       } else {        // If $dirname is a file, simply remove it
+                               $OK = unlink($path);
+                       }
+
+                       clearstatcache();
+               }
+
+               return $OK;
+       }
+
+       /**
         * Returns an array with the names of folders in a specific path
         * Will return 'error' (string) if there were an error with reading directory content.
         * Usage: 11
index 789e478..f2c2b40 100755 (executable)
@@ -435,11 +435,7 @@ class t3lib_extFileFunctions extends t3lib_basicFileFunctions      {
                                        if ($theFile)   {
                                                if ($this->checkPathAgainstMounts($theFile))    {       // I choose not to append '/' to $theFile here as this will prevent us from deleting mounts!! (which makes sense to me...)
                                                        if ($this->actionPerms['deleteFolderRecursively'] && !$this->dont_use_exec_commands)    {
-                                                                       // No way to do this under windows
-                                                               $cmd = 'rm -Rf "'.$theFile.'"';
-                                                               exec($cmd);             // This is a quite critical command...
-                                                               clearstatcache();
-                                                               if (!@file_exists($theFile))    {
+                                                               if (t3lib_div::rmdir($theFile,true))    {
                                                                        $this->writelog(4,0,2,'Directory "%s" deleted recursively!',Array($theFile));
                                                                        return TRUE;
                                                                } else $this->writelog(4,2,119,'Directory "%s" WAS NOT deleted recursively! Write-permission problem?',Array($theFile));
index b205293..20528b1 100755 (executable)
@@ -6240,22 +6240,9 @@ State was change by %s (username: %s)
                if (t3lib_extMgm::isLoaded('cms'))      {
                        if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageCacheToExternalFiles']) {
                                $cacheDir = PATH_site.'typo3temp/cache_pages';
-                                       // TODO: Replace with t3lib_div::rmdir() when available
-                               if (@is_dir($cacheDir) && false !== ($topDir = @opendir($cacheDir))) {
-                                       while (false !== ($dir = @readdir($topDir))) {
-                                               $curDirName = $cacheDir . '/' . $dir;
-                                               if (@is_dir($curDirName) && $curDirName{0} != '.' && false !== ($curDir = @opendir($curDirName))) {
-                                                       while (false != ($fname = @readdir($curDir))) {
-                                                               $curFName = $curDirName . '/' . $fname;
-                                                               if (@is_file($curFName)) {
-                                                                       @unlink($curFName);
-                                                               }
-                                                       }
-                                                       closedir($curDir);
-                                                       @rmdir($curDirName);
-                                               }
-                                       }
-                                       closedir($topDir);
+                               $retVal = t3lib_div::rmdir($cacheDir,true);
+                               if (!$retVal) {
+                                       t3lib_div::sysLog('Could not remove page cache files in "'.$cacheDir.'"','Core/t3lib_tcemain',2);
                                }
                        }
                        $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages','');