mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
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
This commit is contained in:
parent
6bae5a5dd4
commit
7883835b84
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user