Skip to content

Nightly cores support #3449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@

import java.io.File;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Observable;
import java.util.Observer;

Expand All @@ -49,36 +53,50 @@ public DownloadableContributionsDownloader(File _stagingFolder) {
stagingFolder = _stagingFolder;
}

public File download(DownloadableContribution contribution,
final Progress progress, final String statusText)
throws Exception {
public File download(DownloadableContribution contribution, Progress progress, final String statusText) throws Exception {
URL url = new URL(contribution.getUrl());
final File outputFile = new File(stagingFolder, contribution.getArchiveFileName());
Path outputFile = Paths.get(stagingFolder.getAbsolutePath(), contribution.getArchiveFileName());

// Ensure the existence of staging folder
stagingFolder.mkdirs();
Files.createDirectories(stagingFolder.toPath());

if (!hasChecksum(contribution) && Files.exists(outputFile)) {
Files.delete(outputFile);
}

// Need to download or resume downloading?
if (!outputFile.isFile() || (outputFile.length() < contribution.getSize())) {
download(url, outputFile, progress, statusText);
if (!Files.isRegularFile(outputFile, LinkOption.NOFOLLOW_LINKS) || (Files.size(outputFile) < contribution.getSize())) {
download(url, outputFile.toFile(), progress, statusText);
}

// Test checksum
progress.setStatus(_("Verifying archive integrity..."));
onProgress(progress);
String checksum = contribution.getChecksum();
String algo = checksum.split(":")[0];
if (!FileHash.hash(outputFile, algo).equalsIgnoreCase(checksum)) {
throw new Exception(_("CRC doesn't match. File is corrupted."));
if (hasChecksum(contribution)) {
String algo = checksum.split(":")[0];
if (!FileHash.hash(outputFile.toFile(), algo).equalsIgnoreCase(checksum)) {
throw new Exception(_("CRC doesn't match. File is corrupted."));
}
}

contribution.setDownloaded(true);
contribution.setDownloadedFile(outputFile);
return outputFile;
contribution.setDownloadedFile(outputFile.toFile());
return outputFile.toFile();
}

private boolean hasChecksum(DownloadableContribution contribution) {
String checksum = contribution.getChecksum();
if (checksum == null || checksum.isEmpty()) {
return false;
}

String algo = checksum.split(":")[0];

return algo != null && algo.isEmpty();
}

public void download(URL url, File tmpFile, final Progress progress,
final String statusText) throws Exception {
public void download(URL url, File tmpFile, Progress progress, String statusText) throws Exception {
FileDownloader downloader = new FileDownloader(url, tmpFile);
downloader.addObserver(new Observer() {
@Override
Expand Down