private function downloadFromUpdateApi($release)
{
$indexedReleases = $this->getIndexedReleasesList();
if (array_key_exists($release, $indexedReleases)) {
$content = $indexedReleases[$release];
} else {
if ($release == 'latest') {
$content = array_shift($indexedReleases);
} else {
throw new \RuntimeException(sprintf("Could not find release %s", $release));
}
}
$version = $content['version'];
$url = $content['uri'];
$sha1 = $content['sha1'];
$target = $this->getTempFile();
$cacheFilePath = $this->getCacheFilePath($version);
if (file_exists($cacheFilePath)) {
return $cacheFilePath;
}
$this->downloader->download($url, $target);
$sha1Actual = sha1_file($target);
if ($sha1 != $sha1Actual) {
throw new \RuntimeException("Hash mismatch");
}
copy($target, $cacheFilePath);
return $cacheFilePath;
}