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