[FrameworkBundle] removed clearDir() method in some commands (use Filesystem::remove() instead)

This commit is contained in:
Fabien Potencier 2011-03-21 09:31:04 +01:00
parent 45f9c2fbf4
commit b00a903858
2 changed files with 3 additions and 40 deletions

View File

@ -63,13 +63,10 @@ EOF
throw new \RuntimeException(sprintf('Unable to write %s directory', $this->realCacheDir));
}
$this->clearDir($oldCacheDir);
if (!$input->getOption('warmup')) {
$output->writeln('Clear cache');
rename($realCacheDir, $oldCacheDir);
$this->clearDir($oldCacheDir);
} else {
parent::execute($input, $output);
@ -78,7 +75,8 @@ EOF
rename($this->kernelTmp->getCacheDir(), $realCacheDir);
$output->writeln('Clear the old cache');
$this->clearDir($oldCacheDir);
}
$this->container->get('filesystem')->remove($oldCacheDir);
}
}

View File

@ -73,7 +73,7 @@ EOF
$this->cacheDir
);
$this->clearDir($this->kernelTmp->getCacheDir());
$this->container->get('filesystem')->remove($this->kernelTmp->getCacheDir());
$this->kernelTmp->boot();
unlink($this->kernelTmp->getCacheDir().DIRECTORY_SEPARATOR.$this->kernelTmp->getContainerClass().'.php');
@ -88,39 +88,4 @@ EOF
$warmer->enableOptionalWarmers();
$warmer->warmUp($container->getParameter('kernel.cache_dir'));
}
protected function clearDir($dir)
{
if (is_dir($dir)) {
$finder = new Finder();
$files = $finder
->in($dir)
->getIterator()
;
$array = iterator_to_array($files);
foreach (array_reverse($array) as $file) {
if ($file->isFile()) {
if (!is_writable($file->getPathname())) {
throw new \RuntimeException(sprintf('Unable to delete %s file', $file->getPathname()));
}
unlink($file->getPathname());
} else {
if (!is_writable($file->getPathname())) {
throw new \RuntimeException(sprintf('Unable to delete %s directory', $file->getPathname()));
}
rmdir($file->getPathname());
}
}
if (!is_writable($dir)) {
throw new \RuntimeException(sprintf('Unable to delete %s directory', $dir));
}
rmdir($dir);
}
}
}