Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Move exception handling for downloads - closes #40 #42

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

padraic
Copy link
Collaborator

@padraic padraic commented May 17, 2017

Ensure backup phar (made pre-download) is deleted if download fails.

Ensure backup phar (made pre-download) is deleted if download fails
src/Updater.php Outdated
@@ -137,9 +137,19 @@ public function update()
|| (!is_bool($this->newVersionAvailable) && !$this->hasUpdate())) {
return false;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing space

src/Updater.php Outdated
try {
$this->downloadPhar();
} catch (\Exception $e) {
restore_error_handler();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm why is the restore error handler here?

Should be called within Strategy classes as part of download() methods (if used).
@padraic
Copy link
Collaborator Author

padraic commented May 18, 2017

@theofidry Will need to check those Travis failures...looks like removing one of those calls breaks something.

src/Updater.php Outdated
@@ -498,7 +500,7 @@ protected function validatePhar($phar)

protected function cleanupAfterError()
{
//@unlink($this->getBackupPharFile());
@unlink($this->getBackupPharFile());
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator Author

@padraic padraic May 19, 2017

Choose a reason for hiding this comment

The 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)).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

@padraic padraic added this to the 2.0.0 milestone May 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants