Skip to content

Commit

Permalink
[FrameworkBundle] removed clearDir() method in some commands (use Fil…
Browse files Browse the repository at this point in the history
…esystem::remove() instead)
  • Loading branch information
fabpot committed Mar 21, 2011
1 parent 45f9c2f commit b00a903
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.
Expand Up @@ -63,13 +63,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
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);

Expand All @@ -78,7 +75,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
rename($this->kernelTmp->getCacheDir(), $realCacheDir);

$output->writeln('Clear the old cache');
$this->clearDir($oldCacheDir);
}

$this->container->get('filesystem')->remove($oldCacheDir);
}
}
Expand Up @@ -73,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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');
Expand All @@ -88,39 +88,4 @@ protected function warmUp(ContainerInterface $container)
$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);
}
}
}

0 comments on commit b00a903

Please sign in to comment.