Skip to content

Cannot rename because the target ...DebugProjectContainer.xml already exist #7816

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
webmozart opened this issue Apr 23, 2013 · 6 comments
Closed
Labels

Comments

@webmozart
Copy link
Contributor

I recently frequently get the error "Cannot rename because the target "...app...DebugProjectContainer.xml" already exist.".

I get this error both in web applications (Apache) and on the CLI during testing. The latest CLI backtrace is:

Symfony\Bundle\FrameworkBundle\Tests\Functional\ProfilerTest::testProfilerIsDisabled with data set #0 (false)
Symfony\Component\Filesystem\Exception\IOException: Cannot rename because the target "/tmp/2.3.0-DEV/Profiler/cache/frameworkbundletestprofiler/appFrameworkbundletestprofilerDebugProjectContainer.xml" already exist.

/home/bernhard/Entwicklung/Web/Symfony2/src/Symfony/Component/Filesystem/Filesystem.php:237
/home/bernhard/Entwicklung/Web/Symfony2/src/Symfony/Component/Filesystem/Filesystem.php:455
/home/bernhard/Entwicklung/Web/Symfony2/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ContainerBuilderDebugDumpPass.php:36
/home/bernhard/Entwicklung/Web/Symfony2/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:119
/home/bernhard/Entwicklung/Web/Symfony2/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:589
/home/bernhard/Entwicklung/Web/Symfony2/src/Symfony/Component/HttpKernel/Kernel.php:559
/home/bernhard/Entwicklung/Web/Symfony2/src/Symfony/Component/HttpKernel/Kernel.php:130
/home/bernhard/Entwicklung/Web/Symfony2/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php:43
/home/bernhard/Entwicklung/Web/Symfony2/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php:24

I will provide a backtrace for the web application when I get the error again.

@pborreli
Copy link
Contributor

🐛 I have same issue with 2.3-dev but with DebugProjectContainer.php instead

@jakzal
Copy link
Contributor

jakzal commented Apr 23, 2013

This is a regression introduced by #7753. It introduced the Filesystem::dumpFile() method which uses Filesystem::rename() internally. The later throws an exception if a file already exists. ConfigCache, which was used before in place of Filesystem, simply uses the rename function which overwrites an existing file.

@stof
Copy link
Member

stof commented Apr 23, 2013

@mpdude could you have a look at this ?

@mpdude
Copy link
Contributor

mpdude commented Apr 23, 2013

@bschussek That probably happens when you change f. e. a service definition so the container has to be rebuilt?

@webmozart
Copy link
Contributor Author

@mpdude Yes I think it happens when the container has to be rebuitl.

@mpdude
Copy link
Contributor

mpdude commented Apr 23, 2013

#7820 should at least mitigate it for the time being, also if it might change in details. Thanks @jakzal!

fabpot added a commit that referenced this issue Apr 24, 2013
This PR was merged into the master branch.

Discussion
----------

[Filesystem] Made sure Filesystem::dumpFile() overwrites an existing file

#7753 introduced a change in behaviour. Before, ConfigCache simply used the ``rename()`` function to save a file. It was replaced by ``Filesystem::dumpFile()`` which internally uses ``Filesystem::rename()``. The later checks if file already exists and throws an exception if it exists.

This PR makes sure that ``Filesystem::dumpFile()`` removes the file before creating a new one.

Alternatively, we could introduce a third parameter to the ``Filesystem::rename()`` which would allow to overwrite the target file.

Before #7752:
* [CompilerDebugDumpPass](https://github.com/symfony/symfony/blob/d100ffaf761b46acdb2440c04602378b87b0d610/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CompilerDebugDumpPass.php#L23) uses ConfigCache
* [ConfigCache](https://github.com/symfony/symfony/blob/d100ffaf761b46acdb2440c04602378b87b0d610/src/Symfony/Component/Config/ConfigCache.php#L103) uses the [rename()](http://uk1.php.net/rename) function (which overwrites a file if it exists)

After #7752:
* [CompilerDebugDumpPass](https://github.com/symfony/symfony/blob/ad47bc47380188041b7889f40e380ad3766a0110/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CompilerDebugDumpPass.php#L23) uses the ``Filesystem::dumpFile()``
* [Filesystem::dumpFile()](https://github.com/webfactory/symfony/blob/ad47bc47380188041b7889f40e380ad3766a0110/src/Symfony/Component/Filesystem/Filesystem.php#L458) uses the [Filesystem::rename()](https://github.com/webfactory/symfony/blob/ad47bc47380188041b7889f40e380ad3766a0110/src/Symfony/Component/Filesystem/Filesystem.php#L239) (which throws an exception if file exists)

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

Commits
-------

4f4ec76 [Filesystem] Made sure Filesystem::dumpFile() overwrites an existing file.
@fabpot fabpot closed this as completed Apr 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants