/** * Aggregate interface to perform system-wide cache update * @param string|array $path * @param boolean $recursive * @throws \InvalidArgumentException */ public function updateAll($path = null, $recursive = false) { if (!is_null($path)) { if (is_string($path)) { $dir = new \qio\Directory($path); } elseif ($path instanceof \qio\Directory) { $dir = $path; } else { throw new \InvalidArgumentException(); } } else { $dir = $this->cache->getDirectory(); } $path = $dir->getPath(); $stream = new \qio\Directory\Stream($dir); $reader = new \qio\Directory\Reader($stream); if ($stream->open()) { $files = []; while ($value = $reader->readPath()) { if (is_file($path . $value)) { $files[] = $value; } elseif (is_dir($path . $value) && $recursive) { $files = array_merge($files, $this->updateAll(new \qio\Directory($value), $recursive)); } } $stream->close(); $this->update($files); } }
function testFileCacheUpdateAll() { $stream = new \qio\Directory\Stream($this->target); $reader = new \qio\Directory\Reader($stream); $state = new \qio\File\Asset\State($this->cache); $state->updateAll(); $list = $reader->scan(); $this->assertEquals(2, count($list)); }
function testDirectoryScan() { $dir = new \qio\Directory(__DIR__); $stream = new \qio\Directory\Stream($dir); $reader = new \qio\Directory\Reader($stream); $stream->open(); $scan = $reader->scan(); $stream->close(); $this->assertTrue(count($scan) > 0); }