public function downloadUpdateFile(UpdateInfo $update, string $apiEndpoint = 'download') : UpdateFile
{
if ($this->localUpdateFile instanceof UpdateFile) {
$this->log('Local update file used', LogLevel::DEBUG);
return $this->localUpdateFile;
}
try {
$version = $update->getVersion();
$body = $this->hail->postReturnBody($update->getChannel() . API::get($apiEndpoint), ['type' => \get_class($this), 'supplier' => $update->getSupplierName(), 'package' => $update->getPackageName(), 'version' => $version]);
$outFile = \Airship\tempnam('airship-', $this->ext);
$saved = \file_put_contents($outFile, $body);
if ($saved !== false) {
// To prevent TOCTOU issues down the line
$hash = Util::hash($body);
$body = null;
\clearstatcache();
return new UpdateFile(['path' => $outFile, 'version' => $version, 'hash' => $hash, 'size' => \filesize($outFile)]);
}
// If we're still here...
throw new TransferException();
} catch (TransferException $ex) {
$this->log('Automatic update failure.', LogLevel::WARNING, ['exception' => \Airship\throwableToArray($ex), 'channel' => $update->getChannel()]);
// Rethrow it to prevent errors on return type
throw $ex;
}
}