diff --git a/Nette/Caching/FileStorage.php b/Nette/Caching/FileStorage.php index 01d7f5bcf3..30f7ca0854 100644 --- a/Nette/Caching/FileStorage.php +++ b/Nette/Caching/FileStorage.php @@ -266,13 +266,8 @@ public function clean(array $conds) // cleaning using file iterator if ($all || $collector) { $now = time(); - $base = $this->dir . DIRECTORY_SEPARATOR . 'c'; - $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->dir), \RecursiveIteratorIterator::CHILD_FIRST); - foreach ($iterator as $entry) { + foreach (Nette\Finder::find('/c*', '/c*/*')->from($this->dir)->limitDepth(1)->childFirst() as $entry) { $path = (string) $entry; - if (strncmp($path, $base, strlen($base))) { // skip files out of cache - continue; - } if ($entry->isDir()) { // collector: remove empty dirs @rmdir($path); // @ - removing dirs is not necessary continue; diff --git a/Nette/Loaders/RobotLoader.php b/Nette/Loaders/RobotLoader.php index 4f3bcd6d02..a7f0a8b1cf 100644 --- a/Nette/Loaders/RobotLoader.php +++ b/Nette/Loaders/RobotLoader.php @@ -44,15 +44,6 @@ class RobotLoader extends AutoLoader /** @var bool */ private $rebuilt = FALSE; - /** @var string */ - private $acceptMask; - - /** @var string */ - private $ignoreMask; - - /** @var array */ - private $disallow = array(); - /** @@ -143,8 +134,6 @@ public function rebuild() */ public function _rebuildCallback() { - $this->acceptMask = self::wildcards2re($this->acceptFiles); - $this->ignoreMask = self::wildcards2re($this->ignoreDirs); foreach ($this->list as $pair) { if ($pair) $this->files[$pair[0]] = $pair[1]; } @@ -216,46 +205,35 @@ private function addClass($class, $file, $time) */ private function scanDirectory($dir) { - if (is_file($dir)) { - if (!isset($this->files[$dir]) || $this->files[$dir] !== filemtime($dir)) { - $this->scanScript($dir); - } - return; - } - - $iterator = dir($dir); - if (!$iterator) return; - - $base = $dir . DIRECTORY_SEPARATOR; - if (is_file($dir . '/netterobots.txt')) { - foreach (file($dir . '/netterobots.txt') as $s) { - if ($matches = String::match($s, '#^disallow\\s*:\\s*(\\S+)#i')) { - $this->disallow[$base . str_replace('/', DIRECTORY_SEPARATOR, trim($matches[1], '/'))] = TRUE; - } - } - if (isset($this->disallow[$base])) return; - } - - while (FALSE !== ($entry = $iterator->read())) { - if ($entry == '.' || $entry == '..' || isset($this->disallow[$path = $base . $entry])) continue; - - // process subdirectories - if (is_dir($path)) { - // check ignore mask - if (!String::match($entry, $this->ignoreMask)) { - $this->scanDirectory($path); + $disallow = array(); + $iterator = new \AppendIterator; + $iterator->append(new \ArrayIterator(array(new \SplFileInfo($dir)))); + if (is_dir($dir)) { + $iterator->append(Nette\Finder::find(String::split($this->acceptFiles, '#[,\s]+#')) + ->from($dir) + ->exclude(String::split($this->ignoreDirs, '#[,\s]+#')) + ->filter(function($file) use (&$disallow){ + return !isset($disallow[$file->getPathname()]); + })->getIterator() + ); + }; + + foreach ($iterator as $entry) { + $path = (string) $entry; + if ($entry->isDir() && is_file("$path/netterobots.txt")) { + foreach (file("$path/netterobots.txt") as $s) { + if ($matches = String::match($s, '#^disallow\\s*:\\s*(\\S+)#i')) { + $disallow[$path . str_replace('/', DIRECTORY_SEPARATOR, '/' . trim($matches[1], '/'))] = TRUE; + } } - continue; } - if (is_file($path) && String::match($entry, $this->acceptMask)) { + if ($entry->isFile()) { if (!isset($this->files[$path]) || $this->files[$path] !== filemtime($path)) { $this->scanScript($path); } } } - - $iterator->close(); } @@ -338,25 +316,6 @@ private function scanScript($file) - /** - * Converts comma separated wildcards to regular expression. - * @param string - * @return string - */ - private static function wildcards2re($wildcards) - { - $mask = array(); - foreach (explode(',', $wildcards) as $wildcard) { - $wildcard = trim($wildcard); - $wildcard = addcslashes($wildcard, '.\\+[^]$(){}=!><|:#'); - $wildcard = strtr($wildcard, array('*' => '.*', '?' => '.')); - $mask[] = $wildcard; - } - return '#^(' . implode('|', $mask) . ')$#i'; - } - - - /********************* backend ****************d*g**/