Make WordPress Core

Ticket #2223: cache.php.diff

File cache.php.diff, 1.6 KB (added by ringmaster, 19 years ago)

Patch alluded to in comments.

  • cache.php

     
    235235                $dir = rtrim($dir, DIRECTORY_SEPARATOR);
    236236                $top_dir = $dir;
    237237                $stack = array($dir);
     238                $index = 0;
    238239
    239                 while (count($stack)) {
    240                         # Get last directory on stack
    241                         $dir = end($stack);
     240                while ($index < count($stack)) {
     241                        # Get indexed directory from stack
     242                        $dir = $stack[$index];
    242243     
    243244                        $dh = @ opendir($dir);
    244245                        if (!$dh)
     
    247248                        while (($file = @ readdir($dh)) !== false) {
    248249                                if ($file == '.' or $file == '..')
    249250                                        continue;
    250 
     251                                       
    251252                                if (@ is_dir($dir . DIRECTORY_SEPARATOR . $file))
    252253                                        $stack[] = $dir . DIRECTORY_SEPARATOR . $file;
    253254                                else if (@ is_file($dir . DIRECTORY_SEPARATOR . $file))
    254255                                        @ unlink($dir . DIRECTORY_SEPARATOR . $file);
    255256                        }
    256257
    257                         if (end($stack) == $dir) {
    258                                 if ( $dir != $top_dir)
    259                                         @ rmdir($dir);
    260                                 array_pop($stack);
    261                         }
     258                        $index++;
    262259                }
     260
     261                $stack = array_reverse($stack);  // Last added dirs are deepest
     262                foreach($stack as $dir) {
     263                        if ( $dir != $top_dir)
     264                                @ rmdir($dir);
     265                }
     266
    263267        }
    264268
    265269        function release_lock() {
     
    403407                if (defined('CACHE_PATH'))
    404408                        $this->cache_dir = CACHE_PATH;
    405409                else
    406                         $this->cache_dir = ABSPATH.'wp-content/cache/';
     410                        // Using the correct separator eliminates some cache flush errors on Windows
     411                        $this->cache_dir = ABSPATH.'wp-content'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
    407412
    408413                if (is_writable($this->cache_dir) && is_dir($this->cache_dir)) {
    409414                                $this->cache_enabled = true;