Skip to content

Mitigate dependency upon ConfigCache #7753

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
wants to merge 9 commits into from
Closed

Mitigate dependency upon ConfigCache #7753

wants to merge 9 commits into from

Conversation

mpdude
Copy link
Contributor

@mpdude mpdude commented Apr 21, 2013

Q A
Bug fix? no
New feature? yes (refactoring)
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR todo, issue is symfony/symfony-docs#2531

Some clients use ConfigCache only for its ability to atomically write into a file.

The PR moves that code into the Filesystem component.

It's a pick off #7230.

To-Do:

  • Update docs for the Filesystem component

@mpdude
Copy link
Contributor Author

mpdude commented Apr 21, 2013

Travis exited with a segfault on PHP 5.3.3 only...?!?

@jakzal
Copy link
Contributor

jakzal commented Apr 21, 2013

@mpdude yes, it's not your fault though. The problem exist for some time now (see #7754).

@fabpot
Copy link
Member

fabpot commented Apr 21, 2013

Thanks for working on smaller PRs. That's much appreciated, and it definitely makes things easier.

Unfortunately, this one cannot be merged as it would introduce a hard dependency between HttpKernel and Config for instance, which we must avoid as some projects using Symfony do not want to depend on Config (like Drupal for instance).

As a rule of thumb, code duplication in Symfony exists for a reason, so refactoring like this one will almost always be rejected.

@mpdude
Copy link
Contributor Author

mpdude commented Apr 21, 2013

I was aware of that need of f. e. Drupal, but somehow failed to see the new dep here. Sorry.

Better now?

@fabpot
Copy link
Member

fabpot commented Apr 21, 2013

What about moving CacheFileUtils::dumpInFile() to the Filsystem component class instead? And remove the other two methods that are not used anyway.

The only client of these methods was removed in 669898b.
@mpdude
Copy link
Contributor Author

mpdude commented Apr 21, 2013

Regarding the Filesystem component: Good idea and better place, but would be a change dependency-wise? Component/Config then would need Component/Filesystem. Bundle/FrameworkBundle/* probably don't care...

@fabpot
Copy link
Member

fabpot commented Apr 21, 2013

Adding the Filesystem component as a dep to Config is not a problem.

@fabpot
Copy link
Member

fabpot commented Apr 21, 2013

For the method name in Filesystem, we should probably come up with a better name than dumpInFile. dumpFile or storeFile should be enough, no?

@mpdude
Copy link
Contributor Author

mpdude commented Apr 21, 2013

Great, yes, will do.

}

$this->rename($tmpFile, $filename);
$this->chmod($filename, $mode);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how it was before, but wouldn't it be better to chmod() first before moving the file in place?

@fabpot
Copy link
Member

fabpot commented Apr 21, 2013

Except for the getMetaFile method, everything else looks good to me. Can you also add a note in the Filesystem CHANGELOG?

@mpdude
Copy link
Contributor Author

mpdude commented Apr 21, 2013

Adding the getMetaFile() was a reflex action as the meta file name is built in two different methods, though I forgot one of the places when picking from #7230. Shall I make it private?

@mpdude
Copy link
Contributor Author

mpdude commented Apr 21, 2013

Just to be sure, don't we have to do anything about the new Config -> Filesystem dep? Add it to the Config component composer.json maybe?

@fabpot
Copy link
Member

fabpot commented Apr 21, 2013

You are right, you need to add the filesystem component as a required dep for the config component.

@fabpot
Copy link
Member

fabpot commented Apr 21, 2013

Nervermind, I'm doing to do it after the merge.

@fabpot fabpot closed this in c3756eb Apr 21, 2013
@mpdude
Copy link
Contributor Author

mpdude commented Apr 21, 2013

Thanks, learned a lot already today.

The next picks will probably become much more interesting than that :-)

fabpot added a commit that referenced this pull request Apr 22, 2013
This PR was merged into the master branch.

Discussion
----------

[Filesystem] Added a missing test case for Filesystem::dumpFile()

This PR adds a test case for the ``Filesystem::dumpFile()`` method (introduced in #7753).

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | [![Build Status](https://travis-ci.org/jakzal/symfony.png?branch=dumpfile-tests)](https://travis-ci.org/jakzal/symfony)
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

8fcf4c2 [Filesystem] Added a missing test case for Filesystem::dumpFile().
fabpot added a commit that referenced this pull request 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.
2.3.0
-----

* added the dumpFile() method to atomically write files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo automatically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, thats "atomically" (sic) - writing the file in a way that other user see either the old or the new one, but never a partially-written state.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks! I've learned a new word :)
Could you please review symfony/symfony-docs#2592 , after your comment I'm not sure if it's correct.

@mpdude mpdude deleted the issue-7230/picks/cache-file-utils branch September 24, 2015 19:25
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

Successfully merging this pull request may close these issues.

4 participants