Skip to content

If a downloaded archive is corrupted (CRC error) retry the download #5453

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 2 commits into from
Oct 14, 2016
Merged
Show file tree
Hide file tree
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 @@ -62,20 +62,38 @@ public File download(DownloadableContribution contribution, Progress progress, f
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);
}
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);
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."));
// 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);
Expand Down
113 changes: 40 additions & 73 deletions arduino-core/src/processing/app/i18n/Resources_ach.po
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ msgid ""
"save, your changes will be lost."
msgstr ""

#: Sketch.java:398
#, java-format
msgid "A file named \"{0}\" already exists in \"{1}\""
msgstr ""

#: Editor.java:2169
#, java-format
msgid "A folder named \"{0}\" already exists. Can't open sketch."
Expand Down Expand Up @@ -415,8 +410,10 @@ msgstr ""
msgid "Burning bootloader to I/O Board (this may take a minute)..."
msgstr ""

#: ../../../cc/arduino/contributions/DownloadableContributionsDownloader.java:77
msgid "CRC doesn't match. File is corrupted."
#: ../../../../../arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java:91
msgid ""
"CRC doesn't match, file is corrupted. It may be a temporary problem, please "
"retry later."
msgstr ""

#: ../../../processing/app/Base.java:379
Expand All @@ -438,10 +435,6 @@ msgstr ""
msgid "Cancel"
msgstr ""

#: Sketch.java:455
msgid "Cannot Rename"
msgstr ""

#: ../../../processing/app/Base.java:465
msgid "Cannot specify any sketch files"
msgstr ""
Expand Down Expand Up @@ -523,6 +516,11 @@ msgstr ""
msgid "Could not copy to a proper location."
msgstr ""

#: ../../../../../arduino-core/src/processing/app/Sketch.java:342
#, java-format
msgid "Could not create directory \"{0}\""
msgstr ""

#: Editor.java:2179
msgid "Could not create the sketch folder."
msgstr ""
Expand All @@ -541,11 +539,6 @@ msgstr ""
msgid "Could not delete the existing ''{0}'' file."
msgstr ""

#: Base.java:2533 Base.java:2556
#, java-format
msgid "Could not delete {0}"
msgstr ""

#: ../../../processing/app/debug/TargetPlatform.java:74
#, java-format
msgid "Could not find boards.txt in {0}. Is it pre-1.5?"
Expand Down Expand Up @@ -602,23 +595,6 @@ msgstr ""
msgid "Could not remove old version of {0}"
msgstr ""

#: Sketch.java:483 Sketch.java:528
#, java-format
msgid "Could not rename \"{0}\" to \"{1}\""
msgstr ""

#: Sketch.java:475
msgid "Could not rename the sketch. (0)"
msgstr ""

#: Sketch.java:496
msgid "Could not rename the sketch. (1)"
msgstr ""

#: Sketch.java:503
msgid "Could not rename the sketch. (2)"
msgstr ""

#: Base.java:2492
#, java-format
msgid "Could not replace {0}"
Expand Down Expand Up @@ -907,11 +883,6 @@ msgstr ""
msgid "Error while compiling: missing '{0}' configuration parameter"
msgstr ""

#: SketchCode.java:83
#, java-format
msgid "Error while loading code {0}"
msgstr ""

#: Editor.java:2567
msgid "Error while printing."
msgstr ""
Expand Down Expand Up @@ -952,8 +923,14 @@ msgstr ""
msgid "Examples"
msgstr ""

#: ../../../../../app/src/processing/app/Base.java:1267
msgid "Examples from Built-in Libraries"
#: ../../../../../app/src/processing/app/Base.java:1226
msgid "Examples for any board"
msgstr ""

#: ../../../../../app/src/processing/app/Base.java:1246
#: ../../../../../app/src/processing/app/Base.java:1257
#, java-format
msgid "Examples for {0}"
msgstr ""

#: ../../../../../app/src/processing/app/Base.java:1244
Expand All @@ -964,12 +941,6 @@ msgstr ""
msgid "Examples from Other Libraries"
msgstr ""

#: ../../../../../app/src/processing/app/Base.java:1287
#: ../../../../../app/src/processing/app/Base.java:1298
#, java-format
msgid "Examples from {0} Libraries"
msgstr ""

#: ../../../../../app/src/processing/app/Editor.java:753
msgid "Export canceled, changes must first be saved."
msgstr ""
Expand All @@ -983,6 +954,15 @@ msgstr ""
msgid "Failed to open sketch: \"{0}\""
msgstr ""

#: ../../../../../arduino-core/src/processing/app/SketchFile.java:183
#, java-format
msgid "Failed to rename \"{0}\" to \"{1}\""
msgstr ""

#: ../../../../../arduino-core/src/processing/app/Sketch.java:298
msgid "Failed to rename sketch folder"
msgstr ""

#: Editor.java:491
msgid "File"
msgstr ""
Expand Down Expand Up @@ -1954,9 +1934,9 @@ msgid ""
"need to re-save this sketch to another location."
msgstr ""

#: Sketch.java:457
#: ../../../../../arduino-core/src/processing/app/Sketch.java:246
#, java-format
msgid "Sorry, a sketch (or folder) named \"{0}\" already exists."
msgid "Sorry, the folder \"{0}\" already exists."
msgstr ""

#: Preferences.java:115
Expand Down Expand Up @@ -2042,11 +2022,8 @@ msgid ""
"(ASCII only and no spaces, and it cannot start with a number)"
msgstr ""

#: Sketch.java:374
msgid ""
"The main file can't use an extension.\n"
"(It may be time for your to graduate to a\n"
"\"real\" programming environment)"
#: ../../../../../app/src/processing/app/SketchController.java:170
msgid "The main file cannot use an extension"
msgstr ""

#: Sketch.java:356
Expand All @@ -2070,6 +2047,11 @@ msgid ""
"{1}"
msgstr ""

#: ../../../../../arduino-core/src/processing/app/Sketch.java:272
#, java-format
msgid "The sketch already contains a file named \"{0}\""
msgstr ""

#: Sketch.java:1755
msgid ""
"The sketch folder has disappeared.\n"
Expand Down Expand Up @@ -2453,26 +2435,10 @@ msgstr ""
msgid "You can't fool me"
msgstr ""

#: Sketch.java:411
msgid "You can't have a .cpp file with the same name as the sketch."
msgstr ""

#: ../../../../../app/src/processing/app/Base.java:2312
msgid "You can't import a folder that contains your sketchbook"
msgstr ""

#: Sketch.java:421
msgid ""
"You can't rename the sketch to \"{0}\"\n"
"because the sketch already has a .cpp file with that name."
msgstr ""

#: ../../../../../app/src/processing/app/Sketch.java:659
msgid ""
"You can't save the sketch as \"{0}\"\n"
"because the sketch already has a file with that name."
msgstr ""

#: Sketch.java:883
msgid ""
"You cannot save the sketch into a folder\n"
Expand Down Expand Up @@ -2591,10 +2557,6 @@ msgstr ""
msgid "connected!"
msgstr ""

#: Sketch.java:540
msgid "createNewFile() returned false"
msgstr ""

#: ../../../../../app/src/processing/app/Editor.java:1352
msgid "http://www.arduino.cc/"
msgstr ""
Expand Down Expand Up @@ -2732,3 +2694,8 @@ msgstr ""
#, java-format
msgid "{0}: Unknown package"
msgstr ""

#: ../../../../../arduino-core/src/processing/app/Platform.java:223
#, java-format
msgid "{0}Install{1} the package to use your {2}"
msgstr ""
Loading