Skip to content

dumpFile(), preserve existing file permissions #21823

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 3 commits into from
Closed

dumpFile(), preserve existing file permissions #21823

wants to merge 3 commits into from

Conversation

chs2
Copy link
Contributor

@chs2 chs2 commented Mar 1, 2017

When calling Filesystem::dumpFile() on an already existing file, its permissions are lost.

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

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

should be applied to 2.7

@@ -646,7 +646,12 @@ public function dumpFile($filename, $content)
throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
}

@chmod($tmpFile, 0666 & ~umask());
Copy link
Member

Choose a reason for hiding this comment

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

what about using the ternary op?
@chmod($tmpFile, !file_exists($filename) ? 0666 & ~umask() : fileperms($filename))

Copy link
Contributor Author

@chs2 chs2 Mar 5, 2017

Choose a reason for hiding this comment

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

It may depend on what is considered the most readable.
By the way, what about $this -> chmod() instead of chmod() ?

Copy link
Member

Choose a reason for hiding this comment

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

$this->chmod wouldn't provide much more to me, except the exception on error, but I don't see it as needed here

Copy link
Member

Choose a reason for hiding this comment

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

I like the ternary op because it's not too long ... but I'd check a positive condition because negative conditions are less readable:

@chmod($tmpFile, file_exists($filename) ? fileperms($filename) : 0666 & ~umask());

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Mar 6, 2017
Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

👍 (for 2.7 to me)

@fabpot
Copy link
Member

fabpot commented Mar 6, 2017

@chs2 Can you change the target branch to 2.7 (and resolve the conflicts there)?

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

👍

@chs2 chs2 changed the base branch from master to 2.7 March 6, 2017 17:05
@chs2
Copy link
Contributor Author

chs2 commented Mar 6, 2017

Resolving the conflict will take a little time.
I may have reached the limitations of my git(hub) knowledges.
I'm even sure of the correct way to acccomplish the switch of target branch and the conflict resolving.
Any tips ?

@fabpot
Copy link
Member

fabpot commented Mar 6, 2017

The easiest is probably to close this PR and open a new one :)

chs2 added 3 commits March 6, 2017 19:13
When calling Filesystem::dumpFile() on an already existing file, its permissions are lost.
@xabbuh
Copy link
Member

xabbuh commented Mar 6, 2017

@chs2 I rebased your PR for you.

@fabpot
Copy link
Member

fabpot commented Mar 6, 2017

Thank you @chs2.

fabpot added a commit that referenced this pull request Mar 6, 2017
This PR was squashed before being merged into the 2.7 branch (closes #21823).

Discussion
----------

dumpFile(), preserve existing file permissions

When calling Filesystem::dumpFile() on an already existing file, its permissions are lost.

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->

<!--
- Bug fixes must be submitted against the lowest branch where they apply
  (lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the master branch.
- Please fill in this template according to the PR you're about to submit.
- Replace this comment by a description of what your PR is solving.
-->

Commits
-------

040a9ab dumpFile(), preserve existing file permissions
@fabpot fabpot closed this Mar 6, 2017
@xabbuh
Copy link
Member

xabbuh commented Mar 6, 2017

see #21902 that resolves the failing test case

fabpot added a commit that referenced this pull request Mar 6, 2017
…abbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[Filesystem] respect the umask argument in dumpFile()

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

In #21823 we introduced a small BC break: The `dumpFile()` method of the `Filesystem` class allowed to pass the desired file permissions (support for this feature was dropped in Symfony 3.0).

Commits
-------

3a7cd08 respect the umask argument in dumpFile()
@fabpot fabpot mentioned this pull request Mar 9, 2017
This was referenced Apr 4, 2017
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.

6 participants