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

main
Jordi Boggiano 12 years ago
parent 8f24a04a1d
commit 7b87d2b573

@ -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>");

Loading…
Cancel
Save