Skip to content

Commit 2cad6bb

Browse files
Nyholmnicolas-grekas
authored andcommitted
[FrameworkBundle] Bugfixes in buildDir in the CacheClear command
1 parent 87920d2 commit 2cad6bb

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

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

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,27 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8383
$realCacheDir = $kernel->getContainer()->getParameter('kernel.cache_dir');
8484
// the old cache dir name must not be longer than the real one to avoid exceeding
8585
// the maximum length of a directory or file path within it (esp. Windows MAX_PATH)
86-
$oldBuildDir = substr($realBuildDir, 0, -1).('~' === substr($realBuildDir, -1) ? '+' : '~');
8786
$oldCacheDir = substr($realCacheDir, 0, -1).('~' === substr($realCacheDir, -1) ? '+' : '~');
88-
$fs->remove([$oldBuildDir, $oldCacheDir]);
87+
$fs->remove($oldCacheDir);
8988

90-
if (!is_writable($realBuildDir)) {
91-
throw new RuntimeException(sprintf('Unable to write in the "%s" directory.', $realBuildDir));
92-
}
9389
if (!is_writable($realCacheDir)) {
9490
throw new RuntimeException(sprintf('Unable to write in the "%s" directory.', $realCacheDir));
9591
}
9692

93+
$useBuildDir = $realBuildDir !== $realCacheDir;
94+
if ($useBuildDir) {
95+
$oldBuildDir = substr($realBuildDir, 0, -1).('~' === substr($realBuildDir, -1) ? '+' : '~');
96+
$fs->remove($oldBuildDir);
97+
98+
if (!is_writable($realBuildDir)) {
99+
throw new RuntimeException(sprintf('Unable to write in the "%s" directory.', $realBuildDir));
100+
}
101+
}
102+
97103
$io->comment(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
98-
$this->cacheClearer->clear($realBuildDir);
104+
if ($useBuildDir) {
105+
$this->cacheClearer->clear($realBuildDir);
106+
}
99107
$this->cacheClearer->clear($realCacheDir);
100108

101109
// The current event dispatcher is stale, let's not use it anymore
@@ -141,7 +149,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
141149
}
142150

143151
if (!$fs->exists($warmupDir.'/'.$containerDir)) {
144-
$fs->rename($realCacheDir.'/'.$containerDir, $warmupDir.'/'.$containerDir);
152+
$fs->rename($realBuildDir.'/'.$containerDir, $warmupDir.'/'.$containerDir);
145153
touch($warmupDir.'/'.$containerDir.'.legacy');
146154
}
147155

@@ -161,31 +169,33 @@ protected function execute(InputInterface $input, OutputInterface $output): int
161169
}
162170
}
163171

164-
if ($oldBuildDir) {
165-
$fs->rename($realBuildDir, $oldBuildDir);
166-
} else {
167-
$fs->remove($realBuildDir);
168-
}
169172
if ($oldCacheDir) {
170173
$fs->rename($realCacheDir, $oldCacheDir);
171174
} else {
172175
$fs->remove($realCacheDir);
173176
}
174177
$fs->rename($warmupDir, $realCacheDir);
175-
// Copy the content of the warmed cache in the build dir
176-
$fs->copy($realCacheDir, $realBuildDir);
178+
179+
if ($useBuildDir) {
180+
$fs->rename($realBuildDir, $oldBuildDir);
181+
// Copy the content of the warmed cache in the build dir
182+
$fs->mirror($realCacheDir, $realBuildDir);
183+
}
177184

178185
if ($output->isVerbose()) {
179186
$io->comment('Removing old build and cache directory...');
180187
}
181188

182-
try {
183-
$fs->remove($oldBuildDir);
184-
} catch (IOException $e) {
185-
if ($output->isVerbose()) {
186-
$io->warning($e->getMessage());
189+
if ($useBuildDir) {
190+
try {
191+
$fs->remove($oldBuildDir);
192+
} catch (IOException $e) {
193+
if ($output->isVerbose()) {
194+
$io->warning($e->getMessage());
195+
}
187196
}
188197
}
198+
189199
try {
190200
$fs->remove($oldCacheDir);
191201
} catch (IOException $e) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy