-
Notifications
You must be signed in to change notification settings - Fork 27
Move exception handling for downloads - closes #40 #42
base: master
Are you sure you want to change the base?
Changes from 1 commit
4820ddf
e8f293a
792ff81
0f353f1
6bdbeef
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 |
---|---|---|
|
@@ -137,9 +137,19 @@ public function update() | |
|| (!is_bool($this->newVersionAvailable) && !$this->hasUpdate())) { | ||
return false; | ||
} | ||
|
||
$this->backupPhar(); | ||
$this->downloadPhar(); | ||
|
||
try { | ||
$this->downloadPhar(); | ||
} catch (\Exception $e) { | ||
restore_error_handler(); | ||
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. hm why is the restore error handler here? |
||
$this->cleanupAfterError(); | ||
throw $e; | ||
} | ||
|
||
$this->replacePhar(); | ||
|
||
return true; | ||
} | ||
|
||
|
@@ -375,13 +385,7 @@ protected function downloadPhar() | |
} | ||
} | ||
|
||
try { | ||
$this->validatePhar($this->getTempPharFile()); | ||
} catch (\Exception $e) { | ||
restore_error_handler(); | ||
$this->cleanupAfterError(); | ||
throw $e; | ||
} | ||
$this->validatePhar($this->getTempPharFile()); | ||
} | ||
|
||
protected function replacePhar() | ||
|
@@ -498,7 +502,7 @@ protected function validatePhar($phar) | |
|
||
protected function cleanupAfterError() | ||
{ | ||
//@unlink($this->getBackupPharFile()); | ||
@unlink($this->getBackupPharFile()); | ||
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. all the files don't necessarily exists so we need to unlink them only if they exists no? 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. That's one solution. The problem is that the errors were being thrown as exceptions as we use an error handler when checking PHAR signatures. If the handler is not restored, it would leak into subsequent code (in this case the unlink() calls with @ suppression ignored in our unit tests, but could also be the user's own code which is probably isn't desired behaviour)). 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. Moved the restoration to the cleanupAfterError function to make it a bit easier to understand why/when called. |
||
@unlink($this->getTempPharFile()); | ||
@unlink($this->getTempPubKeyFile()); | ||
} | ||
|
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.
trailing space