-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
bug #14246 [Filesystem] dumpFile() negates default file permissions #17063
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
Conversation
@@ -523,6 +523,7 @@ public function dumpFile($filename, $content) | |||
} | |||
|
|||
$tmpFile = $this->tempnam($dir, basename($filename)); | |||
$this->chmod($tmpFile, 0666, umask()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apply the mode change after writing to the file, the umask may remove the write permission.
If I understand it correctly, there has been a deprecation added in 2.8 which was never merged into 3.0 and the code was never fixed properly there. If you take a look at the history of Filesystem.php:
This means that the only case where no permissions would be set, would be by passing When you take a look at the 3.0 Filesystem.php, you can see that the permissions are not longer fixed. The only non-deprecated way, which is setting it /cc @xabbuh |
@iltar I think your reasoning is correct and we need to always set the permissions as proposed here. By the way, the solution before Symfony 3.0 was not really atomic, was it? I mean the |
@iltar, this is indeed the case. Code that ran in 2.8 without any deprication message stops working in 3.0 because the |
@hboomsma Would you like to create a pull request for older Symfony versions that swaps the order of the calls? |
@xabbuh sure, which versions should we patch? I'll create a pull request for 2.8 right away. |
Hm, I think we will get other issues when merging this on filesystems that don't allow to change permissions (see #8205). |
@xabbuh you are right, I'll fix it in the same way, it was fixed in the mentioned issue, because if As for the request for 2.8 do you have an open issue for me to mention in the PR? |
@hboomsma I think you can refer to the same issue (it's also talking about the (not)-atomic behaviour). |
Looks like the failure is unrelated to the changes in this PR. |
$tmpFile = $this->tempnam($dir, basename($filename)); | ||
|
||
if (false === @file_put_contents($tmpFile, $content)) { | ||
throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename); | ||
} | ||
|
||
// Ignore for filesystems that do not support umask | ||
@chmod($tempFile, 0666 & ~umask()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this done twice? And what does $tempFile
refer to?
$tmpFile = $this->tempnam($dir, basename($filename)); | ||
|
||
if (false === @file_put_contents($tmpFile, $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 & ~umask()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking umask()
into account here looks like a new feature to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xabbuh, I agree you could see it that way, lets not take the umask into account and create a separate pull request for it.
@xabbuh updated PR to not take the umask into account. |
@@ -1070,13 +1070,19 @@ public function testDumpFile() | |||
{ | |||
$filename = $this->workspace.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'baz.txt'; | |||
|
|||
// skip mode check on Windows | |||
if ('\\' !== DIRECTORY_SEPARATOR) { | |||
$oldMask = umask(0002); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit-test can be simplified now, no need to set the umask anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to explicitly show that the umask does not influence the resulting access permissions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we wanted to improve the tests this way, we should do that on the 2.3
branch imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, removed the extra tests, because I will create a separate pull request for enhancing the test and taking the umask into account for 2.3.
@xabbuh updated pr to not enhance the unit tests, I will create a separate PR for taking the umask into account with the extra tests for 2.3 after this PR is finished. |
👍 Status: Reviewed |
Thank you @hboomsma. |
…rmissions (Hidde Boomsma) This PR was merged into the 3.0 branch. Discussion ---------- bug #14246 [Filesystem] dumpFile() negates default file permissions | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14246 | License | MIT | Doc PR | none Remain BC compatible with Symfony 2.8. Without this change a chmod is needed after calling `dumpFile`, making it non atomic. Commits ------- 53d6d4b bug #14246 [Filesystem] dumpFile() negates default file permissions
…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.
Remain BC compatible with Symfony 2.8.
Without this change a chmod is needed after calling
dumpFile
, making it non atomic.