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

Commit

Permalink
Move exception handling for downloads - closes #40
Browse files Browse the repository at this point in the history
Ensure backup phar (made pre-download) is deleted if download fails
  • Loading branch information
padraic committed May 17, 2017
1 parent 4dae322 commit 4820ddf
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
$this->cleanupAfterError();
throw $e;
}

$this->replacePhar();

return true;
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -498,7 +502,7 @@ protected function validatePhar($phar)

protected function cleanupAfterError()
{
//@unlink($this->getBackupPharFile());
@unlink($this->getBackupPharFile());
@unlink($this->getTempPharFile());
@unlink($this->getTempPubKeyFile());
}
Expand Down

0 comments on commit 4820ddf

Please sign in to comment.