8000 bug #16829 [FrameworkBundle] prevent cache:clear creating too long pa… · symfony/symfony@4cde2d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4cde2d1

Browse files
committed
bug #16829 [FrameworkBundle] prevent cache:clear creating too long paths (Tobion)
This PR was merged into the 2.3 branch. Discussion ---------- [FrameworkBundle] prevent cache:clear creating too long paths | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #15547 #16783 | License | MIT | Doc PR | - Commits ------- 6e279c5 [FrameworkBundle] prevent cache:clear creating too long paths
2 parents d6dd9a4 + 6e279c5 commit 4cde2d1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ protected function configure()
5454
protected function execute(InputInterface $input, OutputInterface $output)
5555
{
5656
$realCacheDir = $this->getContainer()->getParameter('kernel.cache_dir');
57-
$oldCacheDir = $realCacheDir.'_old';
57+
// the old cache dir name must not be longer than the real one to avoid exceeding
58+
// the maximum length of a directory or file path within it (esp. Windows MAX_PATH)
59+
$oldCacheDir = substr($realCacheDir, 0, -1).('~' === substr($realCacheDir, -1) ? '+' : '~');
5860
$filesystem = $this->getContainer()->get('filesystem');
5961

6062
if (!is_writable($realCacheDir)) {
@@ -75,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7577
// the warmup cache dir name must have the same length than the real one
7678
// to avoid the many problems in serialized resources files
7779
$realCacheDir = realpath($realCacheDir);
78-
$warmupDir = substr($realCacheDir, 0, -1).'_';
80+
$warmupDir = substr($realCacheDir, 0, -1).('_' === substr($realCacheDir, -1) ? '-' : '_');
7981

8082
if ($filesystem->exists($warmupDir)) {
8183
$filesystem->remove($warmupDir);
@@ -100,8 +102,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
100102
*/
101103
protected function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = true)
102104
{
103-
$this->getContainer()->get('filesystem')->remove($warmupDir);
104-
105105
// create a temporary kernel
106106
$realKernel = $this->getContainer()->get('kernel');
107107
$realKernelClass = get_class($realKernel);

0 commit comments

Comments
 (0)
0