diff --git a/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java b/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java index d1cca3061..025991166 100644 --- a/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java +++ b/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java @@ -62,20 +62,38 @@ public class DownloadableContributionsDownloader { Files.delete(outputFile); } - // Need to download or resume downloading? - if (!Files.isRegularFile(outputFile, LinkOption.NOFOLLOW_LINKS) || (Files.size(outputFile) < contribution.getSize())) { - download(url, outputFile.toFile(), progress, statusText, progressListener); - } - - // Test checksum - progress.setStatus(tr("Verifying archive integrity...")); - progressListener.onProgress(progress); - String checksum = contribution.getChecksum(); - if (hasChecksum(contribution)) { - String algo = checksum.split(":")[0]; - if (!FileHash.hash(outputFile.toFile(), algo).equalsIgnoreCase(checksum)) { - throw new Exception(tr("CRC doesn't match. File is corrupted.")); + boolean downloaded = false; + while (true) { + // Need to download or resume downloading? + if (!Files.isRegularFile(outputFile, LinkOption.NOFOLLOW_LINKS) || (Files.size(outputFile) < contribution.getSize())) { + download(url, outputFile.toFile(), progress, statusText, progressListener); + downloaded = true; } + + // Test checksum + progress.setStatus(tr("Verifying archive integrity...")); + progressListener.onProgress(progress); + if (hasChecksum(contribution)) { + String checksum = contribution.getChecksum(); + String algo = checksum.split(":")[0]; + String crc = FileHash.hash(outputFile.toFile(), algo); + if (!crc.equalsIgnoreCase(checksum)) { + // If the file has not been downloaded it may be a leftover of + // a previous download that failed. In this case delete it and + // try to download it again. + if (!downloaded) { + Files.delete(outputFile); + downloaded = true; // Redundant to avoid loops in case delete fails + continue; + } + + // Otherwise throw the error. + throw new Exception(tr("CRC doesn't match, file is corrupted. It may be a temporary problem, please retry later.")); + } + } + + // Download completed successfully + break; } contribution.setDownloaded(true); diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index 9a76cb83b..73f798879 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -5,6 +5,8 @@ ARDUINO 1.6.13 * Fixed regression on command line upload. * Bugifx installing libraries from command line: the IDE tries to update the libraries index but it didn't use it straight away (this caused issues mainly on CI environments) +* Libraries and Boards Managers: if a download error happens (CRC error) the IDE tries to download the file again + without the need to remove the corrupted file manually. [core] * avr: set default values for "upload.verify" and "program.verify" (allows compatibility with older IDE). Thanks @per1234