Skip to content

[2.7][Filesystem] Changed dumpFile to allow dumping to streams... #14580

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

[2.7][Filesystem] Changed dumpFile to allow dumping to streams... #14580

wants to merge 9 commits into from

Conversation

markchalloner
Copy link
Contributor

Q A
Bug fix? yes
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #10018
License MIT
Doc PR symfony/symfony-docs#5320

...as rename can only work where $oldname and $newname have the same streams wrappers.

Added tempNam, stream wrapper aware version of tempnam(), to do the heavy lifting.

$tmpFile = false;
}
}
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I find this method very confusing because of the way the code is structured. I would suggest to omit the break in the end and put it in a guard clause and try to avoid nesting if statements.

Please note the code style as well :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @iltar, sure makes sense, will streamline.

Regarding the code style, are you able to be more specific? I did try to be careful with spacing, variable name and conditions etc. Is it just a case of the things you've already mentioned (simplify, guards, condition nesting)?

Thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

I was mainly referring to the style itself. Usually fabbot.io gives you a patch to fix it, but it seems to not work for some reason. Try using this: http://cs.sensiolabs.org/ I think this is exactly what fabbot.io uses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iltar Ah possibly spacing between blocks. Will update that too. Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iltar. Gotcha.

@markchalloner markchalloner changed the title Changed dumpFile to allow dumping to streams... [2.7][Filesystem] Changed dumpFile to allow dumping to streams... May 8, 2015
@markchalloner
Copy link
Contributor Author

@fabpot. fabbot.io broken on this PR?

*
* @return string The new temporary filename (with path), or FALSE on failure.
*/
public function tempNam($dir, $prefix)
Copy link
Member

Choose a reason for hiding this comment

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

This is a new feature, it should be documented as such.
But do we really want/require it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to add to symfony-docs if this feature is wanted.

Without a stream aware version of tempnam it is very difficult to write to a stream atomically. The path of least resistance becomes writing to the stream non-atomically using file_put_contents, circumventing the benefit of dumpFile. See #10018.

Copy link
Member

Choose a reason for hiding this comment

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

Pleas also add a line in the CHANGELOG of the component.
I'm not convinced by this implementation. What about:

do {
    $tmpnam = $dir.'/'.$prefix.uniqid(mt_rand(), true);
} while (file_exists($tmpnam));

return $tmpnam;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolas-grekas. Thanks for the feedback.

Change log: Will do.

Optimisation, agreed, speed more important than using OS's method of name generation. Will update.

Ta

…andards. Reverted cahnges to dumpFile. Added to CHANGELOG.md and README.md
@markchalloner
Copy link
Contributor Author

Closing this and reopening on #14754:

  • Squashed commit history
  • PR from ticket_XXX branch

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

Successfully merging this pull request may close these issues.

4 participants