summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Lock <josh@linux.intel.com>2011-10-10 17:24:41 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-10-24 17:35:42 +0100
commit64a54dbd73767f7641bbb9462f0f1d01c2316132 (patch)
treebeea9be91d866745fd9f04041e7fad08944af7a8
parente9f66d981ad7ac726988842490192b9b19920445 (diff)
downloadpoky-64a54dbd73767f7641bbb9462f0f1d01c2316132.tar.gz
fetch2: improve usability of checksums
This patch improves the usability of checksums by only requiring one checksum be defined. Further, checksum verification will provide as much information as possible at, rather than a bit at a time. No longer will you need to run fetch, see an md5sum mismatch, fix it, run fetch, seen an sha256sum mismatch, fix it and fetch again. If neither checksum is defined we now report both missing sums at once - rather than one after the other. Finally, if both sums are incorrect, we'll report both incorrect sums at the same time. Fixes part of [YOCTO #1399] (Bitbake rev: 30ca41e596955fcbbe1ae6f4436ecf14cef96f8d) Signed-off-by: Joshua Lock <josh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/fetch2/__init__.py72
1 files changed, 38 insertions, 34 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index fb6138b028..71be6f4b94 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -93,28 +93,6 @@ class ParameterError(BBFetchException):
93 BBFetchException.__init__(self, msg) 93 BBFetchException.__init__(self, msg)
94 self.args = (message, url) 94 self.args = (message, url)
95 95
96class MD5SumError(BBFetchException):
97 """Exception raised when a MD5 checksum of a file does not match for a downloaded file"""
98 def __init__(self, path, wanted, got, url):
99 msg = "File: '%s' has md5 checksum %s when %s was expected (from URL: '%s')" % (path, got, wanted, url)
100 self.url = url
101 self.path = path
102 self.wanted = wanted
103 self.got = got
104 BBFetchException.__init__(self, msg)
105 self.args = (path, wanted, got, url)
106
107class SHA256SumError(MD5SumError):
108 """Exception raised when a SHA256 checksum of a file does not match for a downloaded file"""
109 def __init__(self, path, wanted, got, url):
110 msg = "File: '%s' has sha256 checksum %s when %s was expected (from URL: '%s')" % (path, got, wanted, url)
111 self.url = url
112 self.path = path
113 self.wanted = wanted
114 self.got = got
115 BBFetchException.__init__(self, msg)
116 self.args = (path, wanted, got, url)
117
118class NetworkAccess(BBFetchException): 96class NetworkAccess(BBFetchException):
119 """Exception raised when network access is disabled but it is required.""" 97 """Exception raised when network access is disabled but it is required."""
120 def __init__(self, url, cmd): 98 def __init__(self, url, cmd):
@@ -271,8 +249,8 @@ def verify_checksum(u, ud, d):
271 verify the MD5 and SHA256 checksum for downloaded src 249 verify the MD5 and SHA256 checksum for downloaded src
272 250
273 return value: 251 return value:
274 - True: checksum matched 252 - True: a checksum matched
275 - False: checksum unmatched 253 - False: neither checksum matched
276 254
277 if checksum is missing in recipes file, "BB_STRICT_CHECKSUM" decide the return value. 255 if checksum is missing in recipes file, "BB_STRICT_CHECKSUM" decide the return value.
278 if BB_STRICT_CHECKSUM = "1" then return false as unmatched, otherwise return true as 256 if BB_STRICT_CHECKSUM = "1" then return false as unmatched, otherwise return true as
@@ -285,20 +263,46 @@ def verify_checksum(u, ud, d):
285 md5data = bb.utils.md5_file(ud.localpath) 263 md5data = bb.utils.md5_file(ud.localpath)
286 sha256data = bb.utils.sha256_file(ud.localpath) 264 sha256data = bb.utils.sha256_file(ud.localpath)
287 265
288 if (ud.md5_expected == None or ud.sha256_expected == None): 266 # If strict checking enabled and neither sum defined, raise error
289 logger.warn('Missing SRC_URI checksum for %s, consider adding to the recipe:\n' 267 strict = bb.data.getVar("BB_STRICT_CHECKSUM", d, True) or None
290 'SRC_URI[%s] = "%s"\nSRC_URI[%s] = "%s"', 268 if (strict and ud.md5_expected == None and ud.sha256_expected == None):
291 ud.localpath, ud.md5_name, md5data, 269 raise FetchError('No checksum specified for %s, please add at least one to the recipe:\n'
292 ud.sha256_name, sha256data) 270 'SRC_URI[%s] = "%s"\nSRC_URI[%s] = "%s"', u,
293 if bb.data.getVar("BB_STRICT_CHECKSUM", d, True) == "1": 271 ud.localpath, ud.md5_name, md5data,
294 raise FetchError("No checksum specified for %s." % u, u) 272 ud.sha256_name, sha256data)
295 return 273
274 # Log missing sums so user can more easily add them
275 if ud.md5_expected == None:
276 logger.warn('Missing md5 SRC_URI checksum for %s, consider adding to the recipe:\n'
277 'SRC_URI[%s] = "%s"',
278 ud.localpath, ud.md5_name, md5data)
279
280 if ud.sha256_expected == None:
281 logger.warn('Missing sha256 SRC_URI checksum for %s, consider adding to the recipe:\n'
282 'SRC_URI[%s] = "%s"',
283 ud.localpath, ud.sha256_name, sha256data)
284
285 md5mismatch = False
286 sha256mismatch = False
296 287
297 if ud.md5_expected != md5data: 288 if ud.md5_expected != md5data:
298 raise MD5SumError(ud.localpath, ud.md5_expected, md5data, u) 289 md5mismatch = True
299 290
300 if ud.sha256_expected != sha256data: 291 if ud.sha256_expected != sha256data:
301 raise SHA256SumError(ud.localpath, ud.sha256_expected, sha256data, u) 292 sha256mismatch = True
293
294 # We want to alert the user if a checksum is defined in the recipe but
295 # it does not match.
296 msg = ""
297 if md5mismatch and ud.md5_expected:
298 msg = msg + "\nFile: '%s' has %s checksum %s when %s was expected (from URL: '%s')" % (ud.localpath, 'md5', md5data, ud.md5_expected, u)
299
300 if sha256mismatch and ud.sha256_expected:
301 msg = msg + "\nFile: '%s' has %s checksum %s when %s was expected (from URL: '%s')" % (ud.localpath, 'sha256', sha256data, ud.sha256_expected, u)
302
303 if len(msg):
304 raise FetchError('Checksum mismatch!%s' % msg, u)
305
302 306
303def update_stamp(u, ud, d): 307def update_stamp(u, ud, d):
304 """ 308 """