Skip to content

Commit 7ebecc2

Browse files
committed
DownloadableContributionsDownloader: improve downloading logic and performance
Renamed alreadyDownloadedFileViable to fileAlreadyDownloaded to better reflect what is going on with the download Added file length check to improve performance Reordered the logic of DownloadableContributionsDownloader.download to avoid doing multiple checksums in the case of a good file
1 parent bb1eca0 commit 7ebecc2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

arduino-core/src/cc/arduino/contributions/packages/DownloadableContributionsDownloader.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,14 @@ public File download(DownloadableContribution contribution,
5757
// Ensure the existence of staging folder
5858
stagingFolder.mkdirs();
5959

60-
if (!alreadyDownloadedFileViable(outputFile, contribution)) {
61-
download(url, outputFile, progress, statusText);
60+
if (fileAlreadyDownloaded(outputFile, contribution)) {
61+
contribution.setDownloaded(true);
62+
contribution.setDownloadedFile(outputFile);
63+
return outputFile;
6264
}
6365

66+
download(url, outputFile, progress, statusText);
67+
6468
// Test checksum
6569
progress.setStatus(_("Verifying archive integrity..."));
6670
onProgress(progress);
@@ -82,13 +86,17 @@ private boolean checksumMatches(File outputFile,
8286
return FileHash.hash(outputFile, algo).equals(checksum);
8387
}
8488

85-
private boolean alreadyDownloadedFileViable
89+
private boolean fileAlreadyDownloaded
8690
(File outputFile,
8791
DownloadableContribution contribution) throws Exception {
8892
if (!outputFile.isFile()) {
8993
return false;
9094
}
9195

96+
if (outputFile.length() != contribution.getSize()) {
97+
return false;
98+
}
99+
92100
return checksumMatches(outputFile, contribution);
93101
}
94102

0 commit comments

Comments
 (0)