Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpKernel] Illegal paths in generated container #10976

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

Closed
covex-nn opened this issue May 23, 2014 · 10 comments
Closed

[HttpKernel] Illegal paths in generated container #10976

covex-nn opened this issue May 23, 2014 · 10 comments

Comments

@covex-nn
Copy link

I've tried to optimize performance of vagrant dev-environment running with Symfony 2.3.

So, i moved vendor-dir inside virtual machine from shared folder /vagrant/vendor into /home/vagrant/share/vendor and created symlink from /home/vagrant/share/vendor to /vagrant/vendor

And now on the main page http://www.local/app_dev.php/ there is an error:

Twig_Error_Loader: The "/home/vagrant/app/cache/dev/../../../share/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/views" directory does not exist.

(app_dev.php is inside /vagrant/web dir and app/cache is /vagrant/app/cache)

Inside /vagrant/app/cache/dev/appDevDebugProjectContainer.php file i have this function for twig.loader service:

    protected function getTwig_LoaderService()
    {
        $this->services['twig.loader'] = $instance = new \Symfony\Bundle\TwigBundle\Loader\FilesystemLoader($this->get('templating.locator'), $this->get('templating.name_parser'));

        $instance->addPath('/home'.__DIR__.'/../../../share/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/views', 'Framework');
        $instance->addPath('/home'.__DIR__.'/../../../share/vendor/symfony/symfony/src/Symfony/Bundle/SecurityBundle/Resources/views', 'Security');
        $instance->addPath('/home'.__DIR__.'/../../../share/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Resources/views', 'Twig');
        $instance->addPath('/home'.__DIR__.'/../../../share/vendor/symfony/swiftmailer-bundle/Symfony/Bundle/SwiftmailerBundle/Resources/views', 'Swiftmailer');
        $instance->addPath('/home'.__DIR__.'/../../../share/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Resources/views', 'Doctrine');
        $instance->addPath('/home'.__DIR__.'/../../../share/vendor/apnet/layout-bundle/src/Apnet/LayoutBundle/Resources/views', 'ApnetLayout');
        $instance->addPath('/home'.__DIR__.'/../../../share/vendor/symfony/symfony/src/Symfony/Bundle/WebProfilerBundle/Resources/views', 'WebProfiler');
        $instance->addPath('/home'.__DIR__.'/../../../share/vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/views', 'SensioDistribution');
        $instance->addPath(__DIR__.'/../../Resources/views');
        $instance->addPath('/home'.__DIR__.'/../../../share/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form');

        return $instance;
    }

So, i think that i've found a bug in Symfony\Component\HttpKernel\Kernel::removeAbsolutePathsFromContainer, it came from issue #10894

I think, that there is something wrong with regular expression "{'([^']*)(".preg_quote($rootDir)."[^']*)'}", but i do not know how to fix it =(

But i've changes fixtures for testRemoveAbsolutePathsFromContainer in Symfony\Component\HttpKernel\Tests\KernelTest in https://github.com/covex-nn/symfony/commit/ea654f18fa3ef160e56e95bf88edab3ad78aff80

Here is phpunit output

vagrant@www:/vagrant/symfony$ phpunit src/Symfony/Component/HttpKernel/Tests/KernelTest.php
PHPUnit 4.1.0 by Sebastian Bergmann.

Configuration read from /vagrant/symfony/phpunit.xml.dist

...........................................F.

Time: 602 ms, Memory: 20.50Mb

There was 1 failure:

1) Symfony\Component\HttpKernel\Tests\KernelTest::testRemoveAbsolutePathsFromContainer
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '/some/where/else/foo'
-'/some/ROOT_DIR/ROOT_DIR/foo'
+'/some//vagrant/symfony/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/'.__DIR__.'/../../../foo'

 'file:'.__DIR__.'/profiler'
 '

/vagrant/symfony/src/Symfony/Component/HttpKernel/Tests/KernelTest.php:838

FAILURES!                              
Tests: 45, Assertions: 93, Failures: 1.
@covex-nn
Copy link
Author

Everything works fine with symfony\symfony v2.3.13, bug is in v2.3.14

@Adirelle
Copy link

I have got a similar issue with both 2.4.5 and 2.5.0, which seems linked to #10894.

For performance reason related to VBox shared folders, vendor/, cache/ and logs/ have been moved out of the application folder (one level higher). I have got the same error than @covex-nn, caused by getTwig_LoaderService in cache/dev/appDevDebugProjectContainer.php.

I have found to the following workaround, by changing how the cache and log paths are configured in app/AppKernel.php:

Before:

    public function getCacheDir()
    {
        return __DIR__.'/../../cache/'.$this->environment;
    }

    public function getLogDir()
    {
        return __DIR__.'/../../log/';
    }

After:

    public function getCacheDir()
    {
        return dirname(dirname(__DIR__)).'/cache/'.$this->environment;
    }

    public function getLogDir()
    {
        return dirname(dirname(__DIR__)).'/log/';
    }

@benglass
Copy link

We are also experiencing this issue indirectly, due to the di extra bundle which has a cache warmer for warming up controller annotations. The changes from 2.3.13 to 2.3.14 of converting dumped container paths to absolute seem to indirectly cause the controller file paths you blacklist from di to be modified and then they do not match the paths to the controllers anymore.

@covex-nn
Copy link
Author

Regular expression replaces ROOT_PATH with __DIR__ everywhere in the original path, not only in the begining or after file:

Is there any other path variations except those in https://github.com/symfony/symfony/blob/2.3/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php file ? Can original path has another prefix (not file:) ?

@wimvds
Copy link

wimvds commented May 26, 2014

We also ran into this. The kernel.root_dir that gets injected (since v2.3.14) is screwed up for everything, so you can no longer rely on it in your own service configs.

@fabpot
Copy link
Member

fabpot commented May 26, 2014

Does #10979 fix the issue?

@wimvds
Copy link

wimvds commented May 26, 2014

For us the issue is that kernel.root_dir now contains /path/to/app/cache/environment/../.. instead of just /path/to/app. We used dirname on it to get to the actual project dir, and these calls all break on the relative paths that are returned now (as of 2.3.14). Wrapping it in realpath solved our issue (well, we had to do either that or use a getRootDir() call on the kernel instead which does actually still return the realpath of the root dir)...

@fabpot
Copy link
Member

fabpot commented May 26, 2014

@covex-nn looks like what you mention is exactly the fix done in #10979.

@covex-nn
Copy link
Author

@fabpot no, it does not

Let say, that kernel.root_dir is /vagrant/symfony/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app and composer.json is located in /vagrant/symfony/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app.

Then removeAbsolutePathsFromContainer function will replace '/some/where/else/foo/vagrant/symfony/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers' with '/some/where/else/foo'.__DIR__.'/../../..'

I mean, if some path contains path to composer.json somewhere in the middle, then it will be replaced by __DIR__ with dots in removeAbsolutePathsFromContainer

I made a mistake in my first commit, so I updated test and fixtures. Please see https://github.com/covex-nn/symfony/commit/679075e1af88b9298bcae5f06f38b11286cf729d

Here is PHPUnit output:

There was 1 failure:

1) Symfony\Component\HttpKernel\Tests\KernelTest::testRemoveAbsolutePathsFromContainer
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '/some/where/else/foo'
-'/some/where/else/foo/vagrant/symfony/src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers'
+'/some/where/else/foo'.__DIR__.'/../../..'

 'file:'.__DIR__.'/profiler'
 '

/vagrant/symfony/src/Symfony/Component/HttpKernel/Tests/KernelTest.php:842

@fabpot
Copy link
Member

fabpot commented May 26, 2014

The code has been reverted for now. See #10999 for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants