diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
index 0dada3d7d172f..4181ccd8fd30f 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
@@ -83,19 +83,27 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$realCacheDir = $kernel->getContainer()->getParameter('kernel.cache_dir');
// the old cache dir name must not be longer than the real one to avoid exceeding
// the maximum length of a directory or file path within it (esp. Windows MAX_PATH)
- $oldBuildDir = substr($realBuildDir, 0, -1).('~' === substr($realBuildDir, -1) ? '+' : '~');
$oldCacheDir = substr($realCacheDir, 0, -1).('~' === substr($realCacheDir, -1) ? '+' : '~');
- $fs->remove([$oldBuildDir, $oldCacheDir]);
+ $fs->remove($oldCacheDir);
- if (!is_writable($realBuildDir)) {
- throw new RuntimeException(sprintf('Unable to write in the "%s" directory.', $realBuildDir));
- }
if (!is_writable($realCacheDir)) {
throw new RuntimeException(sprintf('Unable to write in the "%s" directory.', $realCacheDir));
}
+ $useBuildDir = $realBuildDir !== $realCacheDir;
+ if ($useBuildDir) {
+ $oldBuildDir = substr($realBuildDir, 0, -1).('~' === substr($realBuildDir, -1) ? '+' : '~');
+ $fs->remove($oldBuildDir);
+
+ if (!is_writable($realBuildDir)) {
+ throw new RuntimeException(sprintf('Unable to write in the "%s" directory.', $realBuildDir));
+ }
+ }
+
$io->comment(sprintf('Clearing the cache for the
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: