Skip to content

Commit 7883835

Browse files
committed
If an archive is corrupted (CRC error) retry the download
Previously the CRC error was quite annoying to recover because the user needed to manually delete the corrupted file from the staging folder (without knowing the exact path of the file to remove). Now the IDE tries autonomously to resolve the situation by removing the file and downloading it again. Fixes #5394 #4303
1 parent 6bae5a5 commit 7883835

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

Diff for: arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java

+30-12
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,38 @@ public File download(DownloadableContribution contribution, Progress progress, f
6262
Files.delete(outputFile);
6363
}
6464

65-
// Need to download or resume downloading?
66-
if (!Files.isRegularFile(outputFile, LinkOption.NOFOLLOW_LINKS) || (Files.size(outputFile) < contribution.getSize())) {
67-
download(url, outputFile.toFile(), progress, statusText, progressListener);
68-
}
65+
boolean downloaded = false;
66+
while (true) {
67+
// Need to download or resume downloading?
68+
if (!Files.isRegularFile(outputFile, LinkOption.NOFOLLOW_LINKS) || (Files.size(outputFile) < contribution.getSize())) {
69+
download(url, outputFile.toFile(), progress, statusText, progressListener);
70+
downloaded = true;
71+
}
6972

70-
// Test checksum
71-
progress.setStatus(tr("Verifying archive integrity..."));
72-
progressListener.onProgress(progress);
73-
String checksum = contribution.getChecksum();
74-
if (hasChecksum(contribution)) {
75-
String algo = checksum.split(":")[0];
76-
if (!FileHash.hash(outputFile.toFile(), algo).equalsIgnoreCase(checksum)) {
77-
throw new Exception(tr("CRC doesn't match. File is corrupted."));
73+
// Test checksum
74+
progress.setStatus(tr("Verifying archive integrity..."));
75+
progressListener.onProgress(progress);
76+
if (hasChecksum(contribution)) {
77+
String checksum = contribution.getChecksum();
78+
String algo = checksum.split(":")[0];
79+
String crc = FileHash.hash(outputFile.toFile(), algo);
80+
if (!crc.equalsIgnoreCase(checksum)) {
81+
// If the file has not been downloaded it may be a leftover of
82+
// a previous download that failed. In this case delete it and
83+
// try to download it again.
84+
if (!downloaded) {
85+
Files.delete(outputFile);
86+
downloaded = true; // Redundant to avoid loops in case delete fails
87+
continue;
88+
}
89+
90+
// Otherwise throw the error.
91+
throw new Exception(tr("CRC doesn't match, file is corrupted. It may be a temporary problem, please retry later."));
92+
}
7893
}
94+
95+
// Download completed successfully
96+
break;
7997
}
8098

8199
contribution.setDownloaded(true);

Diff for: build/shared/revisions.txt

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ ARDUINO 1.6.13
55
* Fixed regression on command line upload.
66
* Bugifx installing libraries from command line: the IDE tries to update the libraries index but it
77
didn't use it straight away (this caused issues mainly on CI environments)
8+
* Libraries and Boards Managers: if a download error happens (CRC error) the IDE tries to download the file again
9+
without the need to remove the corrupted file manually.
810

911
[core]
1012
* avr: set default values for "upload.verify" and "program.verify" (allows compatibility with older IDE). Thanks @per1234

0 commit comments

Comments
 (0)