Skip to content

[Filesystem] Consider the umask setting when dumping a file #19872

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

Merged
merged 1 commit into from
Sep 14, 2016
Merged

[Filesystem] Consider the umask setting when dumping a file #19872

merged 1 commit into from
Sep 14, 2016

Conversation

leofeyer
Copy link
Contributor

@leofeyer leofeyer commented Sep 6, 2016

Q A
Branch? 3.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #14246 , #17063
License MIT
Doc PR -

Filesystem::dumpFile() does not consider the umask setting and thus creates files with write permissions for everyone (0666). Other chmod() calls in Symfony do consider the umask setting (see e.g. here or here), therefore I have adjusted the dumpFile() method accordingly.

@nicolas-grekas
Copy link
Member

ping @hboomsma since you wrote this line in #17063: any comment here?

@hboomsma
Copy link

hboomsma commented Sep 7, 2016

@nicolas-grekas I original also added the part that would listen to the umask, but that would have been a BC break, so I left it out. I do support the idea of adding it.

👍

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

// Ignore for filesystems that do not support umask
@chmod($tmpFile, 0666);
@chmod($tmpFile, 0666 & ~umask());
Copy link

Choose a reason for hiding this comment

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

Can you also adjust the test case to test this behavior? (be aware of windows not having umask)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is nothing I could adjust, because the Symfony unit test suite explicitly sets the umask to 0, so the expected file permissions in the tests will always be 666 on both Unix and Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hboomsma Ah, I see. Thank you. 😄

@leofeyer leofeyer changed the title Consider the umask setting when dumping a file [Filesystem] Consider the umask setting when dumping a file Sep 8, 2016
@nicolas-grekas
Copy link
Member

@leofeyer can you please rebase so that the merge commit goes away?

@leofeyer
Copy link
Contributor Author

leofeyer commented Sep 8, 2016

Done.

@nicolas-grekas
Copy link
Member

I'd be 👍 here, looks consistent to me.

@jakzal
Copy link
Contributor

jakzal commented Sep 12, 2016

👍

1 similar comment
@hboomsma
Copy link

👍

@fabpot
Copy link
Member

fabpot commented Sep 14, 2016

Thank you @leofeyer.

@fabpot fabpot merged commit fdd266f into symfony:3.1 Sep 14, 2016
fabpot added a commit that referenced this pull request Sep 14, 2016
…e (leofeyer)

This PR was merged into the 3.1 branch.

Discussion
----------

[Filesystem] Consider the umask setting when dumping a file

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

`Filesystem::dumpFile()` does not consider the umask setting and thus creates files with write permissions for everyone (`0666`). Other `chmod()` calls in Symfony do consider the umask setting (see e.g. [here](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/File/File.php#L101) or [here](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/File/UploadedFile.php#L230)), therefore I have adjusted the `dumpFile()` method accordingly.

Commits
-------

fdd266f Consider the umask setting when dumping a file.
@fabpot fabpot mentioned this pull request Oct 3, 2016
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.

7 participants