Skip to content

Commit f39da1f

Browse files
committed
If the checksums or filesizes do not match after download, ask if we should continue.
1 parent 8e1cd03 commit f39da1f

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

lib/inputstreamhelper/utils.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,21 +164,26 @@ def http_download(url, message=None, checksum=None, hash_alg='sha1', dl_size=Non
164164

165165
progress.update(percent, prog_message)
166166

167-
if checksum and calc_checksum.hexdigest() != checksum:
168-
progress.close()
169-
req.close()
170-
log(4, 'Download failed, checksums do not match!')
171-
return False
172-
173-
if dl_size and stat_file(dl_path).st_size() != dl_size:
174-
progress.close()
175-
req.close()
176-
free_space = sizeof_fmt(diskspace())
177-
log(4, 'Download failed, filesize does not match! Filesystem full? Remaining diskspace in temp: {}.'.format(free_space))
178-
return False
179-
180167
progress.close()
181168
req.close()
169+
170+
checksum_ok = (not checksum or calc_checksum.hexdigest() == checksum)
171+
size_ok = (not dl_size or stat_file(dl_path).st_size() == dl_size)
172+
173+
if not all((checksum_ok, size_ok)):
174+
free_space = sizeof_fmt(diskspace())
175+
log(4, 'Something may be wrong with the downloaded file.')
176+
if not checksum_ok:
177+
log(4, 'Provided checksum: {}\nCalculated checksum: {}'.format(checksum, calc_checksum.hexdigest()))
178+
if not size_ok:
179+
free_space = sizeof_fmt(diskspace())
180+
log(4, 'Expected filesize: {}\nReal filesize: {}\nRemaining diskspace: {}'.format(dl_size, stat_file(dl_path).st_size(), free_space))
181+
182+
if yesno_dialog(localize(30003), localize(30070, filename=filename)): # file maybe broken. Continue anyway?
183+
log(4, 'Continuing despite possibly corrupt file!')
184+
else:
185+
return False
186+
182187
store('download_path', dl_path)
183188
return True
184189

resources/language/resource.language.en_gb/strings.po

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ msgctxt "#30002"
2121
msgid "This add-on relies on the proprietary decryption module [B]Widevine CDM[/B] for playback."
2222
msgstr ""
2323

24+
msgctxt "#30003"
25+
msgid "Warning"
26+
msgstr ""
27+
2428
msgctxt "#30004"
2529
msgid "Error"
2630
msgstr ""
@@ -269,6 +273,10 @@ msgctxt "#30069"
269273
msgid "Choose which version to install"
270274
msgstr ""
271275

276+
msgctxt "#30070"
277+
msgid "Something seems wrong with the downloaded {filename}. Shall we try to continue anyway?"
278+
msgstr ""
279+
272280

273281
### INFORMATION DIALOG
274282
msgctxt "#30800"

0 commit comments

Comments
 (0)