-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Bugfixes in buildDir in the CacheClear command #38548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicolas-grekas
merged 1 commit into
symfony:5.x
from
Nyholm:frameworkbundle-cache-clear
Oct 13, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[FrameworkBundle] Bugfixes in buildDir in the CacheClear command
- Loading branch information
commit 2cad6bbbc77a53d833a89cfd6f45c125df9a0803
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true))); | ||
$this->cacheClearer->clear($realBuildDir); | ||
if ($useBuildDir) { | ||
$this->cacheClearer->clear($realBuildDir); | ||
} | ||
$this->cacheClearer->clear($realCacheDir); | ||
|
||
// The current event dispatcher is stale, let's not use it anymore | ||
|
@@ -141,7 +149,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
} | ||
|
||
if (!$fs->exists($warmupDir.'/'.$containerDir)) { | ||
$fs->rename($realCacheDir.'/'.$containerDir, $warmupDir.'/'.$containerDir); | ||
$fs->rename($realBuildDir.'/'.$containerDir, $warmupDir.'/'.$containerDir); | ||
touch($warmupDir.'/'.$containerDir.'.legacy'); | ||
} | ||
|
||
|
@@ -161,31 +169,33 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
} | ||
} | ||
|
||
if ($oldBuildDir) { | ||
$fs->rename($realBuildDir, $oldBuildDir); | ||
} else { | ||
$fs->remove($realBuildDir); | ||
} | ||
if ($oldCacheDir) { | ||
$fs->rename($realCacheDir, $oldCacheDir); | ||
} else { | ||
$fs->remove($realCacheDir); | ||
} | ||
$fs->rename($warmupDir, $realCacheDir); | ||
// Copy the content of the warmed cache in the build dir | ||
$fs->copy($realCacheDir, $realBuildDir); | ||
|
||
if ($useBuildDir) { | ||
$fs->rename($realBuildDir, $oldBuildDir); | ||
// Copy the content of the warmed cache in the build dir | ||
$fs->mirror($realCacheDir, $realBuildDir); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was just a typo: |
||
} | ||
|
||
if ($output->isVerbose()) { | ||
$io->comment('Removing old build and cache directory...'); | ||
} | ||
|
||
try { | ||
$fs->remove($oldBuildDir); | ||
} catch (IOException $e) { | ||
if ($output->isVerbose()) { | ||
$io->warning($e->getMessage()); | ||
if ($useBuildDir) { | ||
try { | ||
$fs->remove($oldBuildDir); | ||
} catch (IOException $e) { | ||
if ($output->isVerbose()) { | ||
$io->warning($e->getMessage()); | ||
} | ||
} | ||
} | ||
|
||
try { | ||
$fs->remove($oldCacheDir); | ||
} catch (IOException $e) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have a separate buildDir and warming the cache. The container will never be located in $warmupDir. It will always be in
$readBuildDir
.If we dont have a separate buildDir. Then $readBuildDir === $readCacheDir`