use of org.nzbhydra.mapping.github.Asset in project nzbhydra2 by theotherp.
the class UpdateManager method installUpdate.
public void installUpdate() throws UpdateException {
Release latestRelease = latestReleaseCache.get();
logger.info("Starting update process to {}", latestRelease.getTagName());
Asset asset = getAsset(latestRelease);
String url = asset.getBrowserDownloadUrl();
logger.debug("Downloading update from URL {}", url);
File updateZip;
try {
File updateFolder = new File(NzbHydra.getDataFolder(), "update");
if (!updateFolder.exists()) {
logger.debug("Creating update folder {}", updateFolder);
Files.createDirectory(updateFolder.toPath());
} else {
logger.debug("Cleaning update folder {}", updateFolder.getAbsolutePath());
FileUtils.cleanDirectory(updateFolder);
}
updateZip = new File(updateFolder, asset.getName());
logger.debug("Saving update file as {}", updateZip.getAbsolutePath());
applicationEventPublisher.publishEvent(new UpdateEvent("Downloading update file"));
webAccess.downloadToFile(url, updateZip);
} catch (RestClientException | IOException e) {
logger.error("Error while download or saving ZIP", e);
throw new UpdateException("Error while downloading, saving or extracting update ZIP", e);
}
if (configProvider.getBaseConfig().getMain().isBackupBeforeUpdate()) {
try {
logger.info("Creating backup before shutting down");
applicationEventPublisher.publishEvent(new UpdateEvent("Creating backup before update"));
backupAndRestore.backup();
} catch (Exception e) {
throw new UpdateException("Unable to create backup before update", e);
}
}
logger.info("Shutting down to let wrapper execute the update");
applicationEventPublisher.publishEvent(new UpdateEvent("Shutting down to let wrapper execute update"));
exitWithReturnCode(UPDATE_RETURN_CODE);
}
Aggregations