1
0
Fork 0

Improve error reporting on downloads and copies, refs #1228

pull/1231/head
Jordi Boggiano 2012-10-18 10:30:32 +02:00
parent 247d1aca41
commit 852c369575
2 changed files with 18 additions and 7 deletions

View File

@ -61,10 +61,10 @@ EOT
unset($phar);
rename($tempFilename, $localFilename);
} catch (\Exception $e) {
@unlink($tempFilename);
if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
throw $e;
}
unlink($tempFilename);
$output->writeln('<error>The download is corrupted ('.$e->getMessage().').</error>');
$output->writeln('<error>Please re-run the self-update command to try again.</error>');
}

View File

@ -103,14 +103,17 @@ class RemoteFilesystem
$this->io->write(" Downloading: <comment>connection...</comment>", false);
}
$errorMessage = null;
$errorMessage = '';
set_error_handler(function ($code, $msg) use (&$errorMessage) {
$errorMessage = preg_replace('{^file_get_contents\(.+?\): }', '', $msg);
if (!ini_get('allow_url_fopen')) {
$errorMessage = 'allow_url_fopen must be enabled in php.ini ('.$errorMessage.')';
if ($errorMessage) {
$errorMessage .= "\n";
}
$errorMessage .= preg_replace('{^file_get_contents\(.*?\): }', '', $msg);
});
$result = file_get_contents($fileUrl, false, $ctx);
if ($errorMessage && !ini_get('allow_url_fopen')) {
$errorMessage = 'allow_url_fopen must be enabled in php.ini ('.$errorMessage.')';
}
restore_error_handler();
// fix for 5.4.0 https://bugs.php.net/bug.php?id=61336
@ -146,9 +149,17 @@ class RemoteFilesystem
// handle copy command if download was successful
if (false !== $result && null !== $fileName) {
$result = (bool) @file_put_contents($fileName, $result);
$errorMessage = '';
set_error_handler(function ($code, $msg) use (&$errorMessage) {
if ($errorMessage) {
$errorMessage .= "\n";
}
$errorMessage .= preg_replace('{^file_put_contents\(.*?\): }', '', $msg);
});
$result = (bool) file_put_contents($fileName, $result);
restore_error_handler();
if (false === $result) {
throw new TransportException('The "'.$fileUrl.'" file could not be written to '.$fileName);
throw new TransportException('The "'.$fileUrl.'" file could not be written to '.$fileName.': '.$errorMessage);
}
}