1
0
Fork 0

Fix self-update saying the download is corrupt when it isn't

pull/582/head
Jordi Boggiano 2012-04-15 18:14:33 +02:00
parent 8f24a04a1d
commit 7b87d2b573
1 changed files with 6 additions and 2 deletions

View File

@ -48,16 +48,20 @@ EOT
$remoteFilename = 'http://getcomposer.org/composer.phar'; $remoteFilename = 'http://getcomposer.org/composer.phar';
$localFilename = $_SERVER['argv'][0]; $localFilename = $_SERVER['argv'][0];
$tempFilename = $localFilename.'temp'; $tempFilename = basename($localFilename, '.phar').'-temp.phar';
$rfs->copy('getcomposer.org', $remoteFilename, $tempFilename); $rfs->copy('getcomposer.org', $remoteFilename, $tempFilename);
try { try {
// test the phar validity
$phar = new \Phar($tempFilename); $phar = new \Phar($tempFilename);
// free the variable to unlock the file
unset($phar);
rename($tempFilename, $localFilename); rename($tempFilename, $localFilename);
} catch (\UnexpectedValueException $e) { } catch (\UnexpectedValueException $e) {
unlink($tempFilename); unlink($tempFilename);
$output->writeln("<error>The download is corrupt. Please re-run the self-update command.</error>"); $output->writeln('<error>The download is corrupt ('.$e->getMessage().').</error>');
$output->writeln('<error>Please re-run the self-update command to try again.</error>');
} }
} else { } else {
$output->writeln("<info>You are using the latest composer version.</info>"); $output->writeln("<info>You are using the latest composer version.</info>");