-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[9.x] Fix Illuminate Filesystem replace() leaves file executable #45856
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
[9.x] Fix Illuminate Filesystem replace() leaves file executable #45856
Conversation
It seems OS is taking precedence over test permission making the permission wrxw-xr--
…s file and updated test
Changing it to 776 doesn't make much sense to me. From my understanding, you should subtract from 777 for directories and 666 for files. So, changing it to 666 is more sensible to me and fixes the issue on my machine. However, a test is failing where the original test (made by a contributor some years ago) uses a "weird" umask of 131. 666 - 131 is not even a real permission afaik so the test is failing. I'm unsure of the value of this particular test or what it is even trying to test. I have fixed the test. |
Just wanted to flag that this PR appears to be the cause of #45890 preventing Laravel apps from building on Heroku. Not sure exactly if this is an issue with the fix in the PR or an underlying issue with Heroku's PHP build pipeline. |
Hi @dwightwatson ! We run on an other PAAS than Heroku and we have the same behavior. |
I would like to get to the bottom of this. This change was correct IMO but is apparently causing build issues on PAAS providers. @dwightwatson - what is the value of "umask()" on your Heroku build pipeline? @potsky? |
I cannot say because it is ran during the build and we have no way to know what is really happening. Here is the end of the build log if it can help:
@taylorotwell I can ask to the PAAS team to make inspections on the build machines if you want. There are very reactive. I can then add some commands in the build on staging to display outputs like this for example in "scripts": {
"post-autoload-dump": [
++ "@php -r \"echo 'UMASK = '.umask();\"",
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi" |
FWIW - Heroku offers an interactive shell for the CI session. It is possible to remote in and poke around a bit if that would be useful. |
Thanks for sharing the umask. That's helpful. I'm used to the umask being 22 on most Linux distributions and on macOS. It being 63 leads to some weird permissions when we try to subtract it as you normally would. |
My macOS shell is currently reporting ¯\_(ツ)_/¯ |
I'm curious if someone can temporarily hardcode Illuminate\Filesystem\Filesystem's chmod call in replace to this: chmod($tempPath, 0644); Does Heroku fail then? |
I'll remote in, update the class, then run the discover command, and see what happens. |
I am going to build with this line in
result in a few minutes but I am quite sure it will work. |
OK - my hunch would be to update the |
It works
|
Yeah, Heroku dynos don't ship with a text editor, so I punted and followed @potsky's technique and it built as well. |
Thanks for letting me know. |
@taylorotwell in protected function write(array $manifest)
{
if (! is_writable($dirname = dirname($this->manifestPath))) {
throw new Exception("The {$dirname} directory must be present and writable.");
}
$this->files->replace(
$this->manifestPath, '<?php return '.var_export($manifest, true).';'
);
} So before replacing or writing the file in So why not doing something like this in $tempPath = tempnam(dirname($path), basename($path));
chmod($tempPath, 0644);
file_put_contents($tempPath, $content);
// AND THEN RESTORE CORRECT PERMISSIONS
chmod($tempPath, 0776 - umask()); |
The issue #45779 is because of changing the permission of file stored in
/tmp
directory giving0775
permission viachmod()
method call withumask()
subtraction.chmod($tempPath, 0777 - umask());
Here we are subtracting the umask() value from 0777
i.e
0777 - 002 = 0775
which in permission isrwxrwxr-x
i.e others is getting read and execute permissionif we change the permission given to
chmod($tempPath, 0776 - umask());
file will have permissionof
0776 - 002 = 0774
which in permission isrwxrwxr--
i.e other is getting read only permissionpassing values in test is a bit confusing for me but I tried doing my best :
in
testFilePermissionRestoredAfterReplace line 100
I have converted 774 into decimal which is after subtracting 2 of umask() from 776, I had to do the assertion with decimal value since$this->getFilePermissions($tempFile)
returns permission value in decimal. ( I think this function name should be getFilePermissionsInDecimal to avoid confusion).After that I updated the permission value in
testReplaceWhenUnixSymlinkExists()
test.