]> code.ossystems Code Review - openembedded-core.git/commitdiff
bitbake/fetch: Checksum validity fixes
authorRichard Purdie <rpurdie@linux.intel.com>
Mon, 20 Dec 2010 16:04:51 +0000 (16:04 +0000)
committerRichard Purdie <rpurdie@linux.intel.com>
Mon, 20 Dec 2010 16:04:51 +0000 (16:04 +0000)
If the checksum check failed, the .md5 stamp file would still have been created
meaning subsequent builds would proceed with the corrupt file. Reorder the calls
to avoid this. Also raise a specific error for the checksum not specified error
case.

Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
bitbake/lib/bb/fetch/__init__.py

index 387de669e1fd4df8816c0c14208a129b6bfb262e..708e39726428f209b984132a2125c6b39003d48e 100644 (file)
@@ -231,7 +231,7 @@ def removefile(f):
     except:
         pass
 
-def verify_checksum(d, ud):
+def verify_checksum(u, ud, d):
     """
     verify the MD5 and SHA256 checksum for downloaded src
 
@@ -245,7 +245,7 @@ def verify_checksum(d, ud):
     """
 
     if not ud.type in ["http", "https", "ftp", "ftps"]:
-        return True
+        return
 
     md5data = bb.utils.md5_file(ud.localpath)
     sha256data = bb.utils.sha256_file(ud.localpath)
@@ -255,17 +255,13 @@ def verify_checksum(d, ud):
                 "SRC_URI[%s] = \"%s\"\nSRC_URI[%s] = \"%s\"" \
                 % (ud.localpath, ud.md5_name, md5data, ud.sha256_name, sha256data))
         if bb.data.getVar("BB_STRICT_CHECKSUM", d, True) == "1":
-            return False
-        else:
-            return True
+            raise FetchError("No checksum specified for %s." % u)
 
     if (ud.md5_expected != md5data or ud.sha256_expected != sha256data):
         bb.error("The checksums for '%s' did not match." % ud.localpath)
         bb.error("Expected MD5: '%s' and Got: '%s'" % (ud.md5_expected, md5data))
         bb.error("Expected SHA256: '%s' and Got: '%s'" % (ud.sha256_expected, sha256data))
-        return False
-
-    return True
+        raise FetchError("%s checksum mismatch." % u)
 
 def go(d, urls = None):
     """
@@ -309,6 +305,9 @@ def go(d, urls = None):
                     raise FetchError("Unable to fetch URL %s from any source." % u)
 
         ud.localpath = localpath
+
+        verify_checksum(u, ud, d)
+
         if os.path.exists(ud.md5):
             # Touch the md5 file to show active use of the download
             try:
@@ -319,9 +318,6 @@ def go(d, urls = None):
         else:
             Fetch.write_md5sum(u, ud, d)
 
-        if not verify_checksum(d, ud):
-            raise FetchError("%s checksum mismatch." % u)
-
         bb.utils.unlockfile(lf)
 
 def checkstatus(d, urls = None):