-
Notifications
You must be signed in to change notification settings - Fork 27
Allow checking for updates with an underprivileged user. Resolve Issue #20 #21
base: master
Are you sure you want to change the base?
Conversation
@@ -327,6 +327,13 @@ protected function newVersionAvailable() | |||
|
|||
protected function backupPhar() | |||
{ | |||
$tempDirectory = $this->getTempDirectory(); |
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.
This block is copy-pasted several times. Maybe it can be moved out to separate method?
I see that this is moved out from setTempDirectory
method. Instead you can:
- move that check into
getTempDirectory
method - use
getTempDirectory
method internally instead of accessingtempDirectory
property directly
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.
Concerning #1, I don't think that will work, because getTempDirectory() method is called in the update check process. That would cause the update check to fail in the same way that required the change (Issue #20 ).
Concerning #2, here in line 330 I am using the getTempDirectory() method as requested and assigning it to a local variable in the method's scope. I don't see a place where I am using the tempDirectory property directly, but please clarify if you see a line where that is done.
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.
Concerning #1, I don't think that will work, because getTempDirectory() method is called in the update check process. That would cause the update check to fail in the same way that required the change (Issue #20 ).
I've tracked back every call of \Humbug\SelfUpdate\Updater::getTempDirectory
and each of them is prefixed by exception throwing when path isn't writable in one way or another. So moving exception throwing into that method would reduce duplication and preserve logic introduced in this PR.
Concerning #2, here in line 330 I am using the getTempDirectory() method as requested and assigning it to a local variable in the method's scope. I don't see a place where I am using the tempDirectory property directly, but please clarify if you see a line where that is done.
I've double checked again and the place is gone. Probably something in the code was changed or I've written my comment theoretically (without looking at the code).
@@ -371,19 +385,41 @@ protected function downloadPhar() | |||
|
|||
protected function replacePhar() | |||
{ | |||
rename($this->getTempPharFile(), $this->getLocalPharFile()); | |||
$localPharFile = $this->getLocalPharFile(); | |||
if (!is_writable($localPharFile)) { |
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.
This code block was moved out from setLocalPharFile
and you can move it to getLocalPharFile
method to avoid duplication.
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.
getLocalPharFile() is also called by setTempDirectory(), which would cause this to fail unnecessarily during a check also. I understand wanting to reduce code duplication, but I think it also makes sense to have these exceptions associated with the code that requires writability, because it prevents these methods from being run without the possibility of running the check first. If you'd really like to avoid duplicating the exceptions, I would propose an interstitial method, like protected isDirectoryWritable($this->getTempDirectory);
which just does the writability check and throws the exception. I decided not to do that originally because it actually creates more lines of code, but perhaps you'd prefer that to the current PR?
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.
Per review by @aik099 prior to merge (or add an issue to review after).
Well, I guess phpoole is basically useless because of this. No way am I going to run it with sudo privs just because this PR isn't merged. |
I don't really understand why phpoole would be useless because of this PR. Just download a newer version available directly or use PHIVE. |
This PR should delay checking for temp and phar file writability until they actually need to be checked, allowing use of the update check command with a user who cannot write to the phar file. This should close Issue #20