Skip to content

Commit

Permalink
bug #25591 [HttpKernel] fix cleaning legacy containers (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.4 branch.

Discussion
----------

[HttpKernel] fix cleaning legacy containers

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

The suffix used to be `.legacyContainer` (length=16) but we forgot to update the length when it was changed to `.legacy` (length=7).

Commits
-------

324821d [HttpKernel] fix cleaning legacy containers
  • Loading branch information
nicolas-grekas committed Dec 28, 2017
2 parents ae6f668 + 324821d commit 89903e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Kernel.php
Expand Up @@ -662,7 +662,7 @@ protected function initializeContainer()
$oldContainerDir = dirname($oldContainer->getFileName());
foreach (glob(dirname($oldContainerDir).'/*.legacy') as $legacyContainer) {
if ($oldContainerDir.'.legacy' !== $legacyContainer && @unlink($legacyContainer)) {
(new Filesystem())->remove(substr($legacyContainer, 0, -16));
(new Filesystem())->remove(substr($legacyContainer, 0, -7));
}
}

Expand Down
27 changes: 26 additions & 1 deletion src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Expand Up @@ -65,6 +65,31 @@ public function testClone()
$this->assertNull($clone->getContainer());
}

public function testInitializeContainerClearsOldContainers()
{
$fs = new Filesystem();
$legacyContainerDir = __DIR__.'/Fixtures/cache/custom/ContainerA123456';
$fs->mkdir($legacyContainerDir);
touch($legacyContainerDir.'.legacy');

$kernel = new CustomProjectDirKernel();
$kernel->boot();

$containerDir = __DIR__.'/Fixtures/cache/custom/'.substr(get_class($kernel->getContainer()), 0, 16);
$this->assertTrue(unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta'));
$this->assertFileExists($containerDir);
$this->assertFileNotExists($containerDir.'.legacy');

$kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); });
$kernel->boot();

$this->assertFileExists($containerDir);
$this->assertFileExists($containerDir.'.legacy');

$this->assertFileNotExists($legacyContainerDir);
$this->assertFileNotExists($legacyContainerDir.'.legacy');
}

public function testBootInitializesBundlesAndContainer()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer'));
Expand Down Expand Up @@ -1022,7 +1047,7 @@ protected function getHttpKernel()

class PassKernel extends CustomProjectDirKernel implements CompilerPassInterface
{
public function __construct(\Closure $buildContainer = null)
public function __construct()
{
parent::__construct();
Kernel::__construct('pass', true);
Expand Down

0 comments on commit 89903e1

Please sign in to comment.