public function download(array $update = []) : InstallFile
{
if ($this->localInstallFile instanceof InstallFile) {
self::$continuumLogger->store(LogLevel::DEBUG, 'Local install file used instead of downloading.', ['installFile' => ['hash' => $this->localInstallFile->getHash(), 'path' => $this->localInstallFile->getPath(), 'signature' => $this->localInstallFile->getSignature(), 'size' => $this->localInstallFile->getSize(), 'version' => $this->localInstallFile->getVersion()]]);
return $this->localInstallFile;
}
// If this was not supplied, we need to get it.
if (empty($update)) {
$update = $this->getPackageData();
}
$supplierName = $this->supplier->getName();
\uasort($update['versions'], function (array $a, array $b) : int {
return (int) ($a['version'] <=> $b['version']);
});
$data = \array_pop($update['versions']);
$version = $data['version'];
$body = $this->hail->postReturnBody($update['channel'] . API::get('download'), ['type' => \get_class($this), 'supplier' => $supplierName, 'package' => $this->package, 'version' => $version]);
$outFile = \Airship\tempnam('airship-', $this->ext);
$saved = \file_put_contents($outFile, $body);
if ($saved === false) {
throw new TransferException();
}
// To prevent TOCTOU issues down the line
$hash = Util::hash($body);
$body = null;
\clearstatcache();
return new InstallFile($this->supplier, ['data' => $data, 'hash' => $hash, 'path' => $outFile, 'size' => \filesize($outFile), 'type' => $this->type, 'version' => $version]);
}