From 7b87d2b5731452769778a3751d226241e75e927d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 15 Apr 2012 18:14:33 +0200 Subject: [PATCH] Fix self-update saying the download is corrupt when it isn't --- src/Composer/Command/SelfUpdateCommand.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index 931c9ea17..659b2e747 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -48,16 +48,20 @@ EOT $remoteFilename = 'http://getcomposer.org/composer.phar'; $localFilename = $_SERVER['argv'][0]; - $tempFilename = $localFilename.'temp'; + $tempFilename = basename($localFilename, '.phar').'-temp.phar'; $rfs->copy('getcomposer.org', $remoteFilename, $tempFilename); try { + // test the phar validity $phar = new \Phar($tempFilename); + // free the variable to unlock the file + unset($phar); rename($tempFilename, $localFilename); } catch (\UnexpectedValueException $e) { unlink($tempFilename); - $output->writeln("The download is corrupt. Please re-run the self-update command."); + $output->writeln('The download is corrupt ('.$e->getMessage().').'); + $output->writeln('Please re-run the self-update command to try again.'); } } else { $output->writeln("You are using the latest composer version.");