Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d3da29

Browse files
jfsimonfabpot
authored andcommitted
[FrameworkBundle] avoids cache:clear to break if new/old folders already exist
1 parent 0e7b5fb commit 1d3da29

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,32 @@ protected function execute(InputInterface $input, OutputInterface $output)
6262
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
6363
}
6464

65+
$filesystem = $this->getContainer()->get('filesystem');
6566
$kernel = $this->getContainer()->get('kernel');
6667
$output->writeln(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
6768

6869
$this->getContainer()->get('cache_clearer')->clear($realCacheDir);
6970

71+
if ($filesystem->exists($oldCacheDir)) {
72+
$filesystem->remove($oldCacheDir);
73+
}
74+
7075
if ($input->getOption('no-warmup')) {
71-
rename($realCacheDir, $oldCacheDir);
76+
$filesystem->rename($realCacheDir, $oldCacheDir);
7277
} else {
7378
$warmupDir = $realCacheDir.'_new';
7479

80+
if ($filesystem->exists($warmupDir)) {
81+
$filesystem->remove($warmupDir);
82+
}
83+
7584
$this->warmup($warmupDir, !$input->getOption('no-optional-warmers'));
7685

77-
rename($realCacheDir, $oldCacheDir);
78-
rename($warmupDir, $realCacheDir);
86+
$filesystem->rename($realCacheDir, $oldCacheDir);
87+
$filesystem->rename($warmupDir, $realCacheDir);
7988
}
8089

81-
$this->getContainer()->get('filesystem')->remove($oldCacheDir);
90+
$filesystem->remove($oldCacheDir);
8291
}
8392

8493
protected function warmup($warmupDir, $enableOptionalWarmers = true)

0 commit comments

Comments
 (0)