-
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?
Changes from all commits
a7596d9
2be819f
850cccd
d12a15a
f557fac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,6 +333,13 @@ protected function newVersionAvailable() | |
|
||
protected function backupPhar() | ||
{ | ||
$tempDirectory = $this->getTempDirectory(); | ||
if (!is_writable($tempDirectory)) { | ||
throw new FilesystemException(sprintf( | ||
'The directory is not writeable: %s.', $tempDirectory | ||
)); | ||
} | ||
|
||
$result = copy($this->getLocalPharFile(), $this->getBackupPharFile()); | ||
if ($result === false) { | ||
$this->cleanupAfterError(); | ||
|
@@ -346,6 +353,13 @@ protected function backupPhar() | |
|
||
protected function downloadPhar() | ||
{ | ||
$tempDirectory = $this->getTempDirectory(); | ||
if (!is_writable($tempDirectory)) { | ||
throw new FilesystemException(sprintf( | ||
'The directory is not writeable: %s.', $tempDirectory | ||
)); | ||
} | ||
|
||
$this->strategy->download($this); | ||
|
||
if (!file_exists($this->getTempPharFile())) { | ||
|
@@ -386,19 +400,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 commentThe reason will be displayed to describe this comment to others. Learn more. This code block was moved out from There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
throw new FilesystemException(sprintf( | ||
'The current phar file is not writeable and cannot be replaced: %s.', | ||
$localPharFile | ||
)); | ||
} | ||
rename($this->getTempPharFile(), $localPharFile); | ||
} | ||
|
||
protected function restorePhar() | ||
{ | ||
$tempDirectory = $this->getTempDirectory(); | ||
if (!is_writable($tempDirectory)) { | ||
throw new FilesystemException(sprintf( | ||
'The directory is not writeable: %s.', $tempDirectory | ||
)); | ||
} | ||
|
||
$backup = $this->getRestorePharFile(); | ||
if (!file_exists($backup)) { | ||
throw new RuntimeException(sprintf( | ||
'The backup file does not exist: %s.', $backup | ||
)); | ||
} | ||
$this->validatePhar($backup); | ||
return rename($backup, $this->getLocalPharFile()); | ||
|
||
$localPharFile = $this->getLocalPharFile(); | ||
if (!is_writable($localPharFile)) { | ||
throw new FilesystemException(sprintf( | ||
'The current phar file is not writeable and cannot be replaced: %s.', | ||
$localPharFile | ||
)); | ||
} | ||
return rename($backup, $localPharFile); | ||
} | ||
|
||
protected function getBackupPharFile() | ||
|
@@ -441,12 +477,6 @@ protected function setLocalPharFile($localPharFile) | |
'The set phar file does not exist: %s.', $localPharFile | ||
)); | ||
} | ||
if (!is_writable($localPharFile)) { | ||
throw new FilesystemException(sprintf( | ||
'The current phar file is not writeable and cannot be replaced: %s.', | ||
$localPharFile | ||
)); | ||
} | ||
$this->localPharFile = $localPharFile; | ||
$this->localPharFileBasename = basename($localPharFile, '.phar'); | ||
} | ||
|
@@ -465,11 +495,6 @@ protected function setLocalPubKeyFile() | |
protected function setTempDirectory() | ||
{ | ||
$tempDirectory = dirname($this->getLocalPharFile()); | ||
if (!is_writable($tempDirectory)) { | ||
throw new FilesystemException(sprintf( | ||
'The directory is not writeable: %s.', $tempDirectory | ||
)); | ||
} | ||
$this->tempDirectory = $tempDirectory; | ||
} | ||
|
||
|
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:getTempDirectory
methodgetTempDirectory
method internally instead of accessingtempDirectory
property directlyThere 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.
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.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).