[jhbuild] extend hash check of tarballs to more algorithms (GNOME bug 587303)



commit 327810ad8b7bc62bcf6889d3b1cc9ba04951fdeb
Author: Frédéric Péters <fpeters 0d be>
Date:   Mon Jul 13 10:53:32 2009 +0200

    extend hash check of tarballs to more algorithms (GNOME bug 587303)
    
    The md5sum attribute is now obsolete, there is a new hash attribute that
    can use any algorithm supported by Python hashlib module, for example:
      <source
        href="http://avahi.org/download/avahi-0.6.25.tar.gz";
        hash="sha256:9220d974f5515b8ccfa3900cd72cedcac0fa4cc87ca3c64405f7c55346cbba59"
        size="1103653"/>

 doc/C/jhbuild.xml                 |   11 +++++++----
 jhbuild/modtypes/tarball.py       |    8 +++++---
 jhbuild/versioncontrol/tarball.py |   29 +++++++++++++++++------------
 modulesets/moduleset.dtd          |    6 ++++--
 modulesets/moduleset.rnc          |    4 +++-
 5 files changed, 36 insertions(+), 22 deletions(-)
---
diff --git a/doc/C/jhbuild.xml b/doc/C/jhbuild.xml
index 1b64d26..bb39aa8 100644
--- a/doc/C/jhbuild.xml
+++ b/doc/C/jhbuild.xml
@@ -2054,8 +2054,9 @@ libgnomecanvas is missing branch definition for gnome-2-20
 	module version.</para>
 
         <para>The <sgmltag class="attribute">size</sgmltag> and <sgmltag
-        class="attribute">md5sum</sgmltag> attributes are optional.
-        If these two attributes are present, they are used to check
+        class="attribute">hash</sgmltag>, as well as the obsolete
+	<sgmltag class="attribte">md5sum</sgmltag>, attributes are optional.
+        If these attributes are present, they are used to check
         that the source package was downloaded correctly.</para>
 
         <para>The <sgmltag class="element">patches</sgmltag> element
@@ -2078,7 +2079,7 @@ libgnomecanvas is missing branch definition for gnome-2-20
         <programlisting>
 &lt;branch module="dbus-python-0.80.2.tar.gz" version="0.80.2"
     repo="dbus/dbus-python"
-    md5sum="2807bc85215c995bd595e01edd9d2077" size="453499"&gt;
+    hash="md5:2807bc85215c995bd595e01edd9d2077" size="453499"&gt;
   &lt;patches&gt;
     &lt;patch file="dbus-glib-build.patch" strip="1" /&gt;
   &lt;/patches&gt;
@@ -2601,6 +2602,7 @@ libgnomecanvas is missing branch definition for gnome-2-20
               [ supports-non-srcdir-builds="<replaceable>yes|no</replaceable>" ]&gt;
     &lt;source href="<replaceable>source-url</replaceable>"
             [ size="<replaceable>source-size</replaceable>" ]
+            [ hash="<replaceable>source-algo:source-hash</replaceable>" ]
             [ md5sum="<replaceable>source-md5sum</replaceable>" ]/&gt;
     &lt;patches&gt;
       &lt;patch file="<replaceable>filename</replaceable>" strip="<replaceable>level</replaceable>"/&gt;
@@ -2624,7 +2626,8 @@ libgnomecanvas is missing branch definition for gnome-2-20
           specifies the file to download and compile.  The <sgmltag
           class="attribute">href</sgmltag> attribute is mandatory, while
           the <sgmltag class="attribute">size</sgmltag> and <sgmltag
-          class="attribute">md5sum</sgmltag> attributes are optional.
+          class="attribute">hash</sgmltag>, as well as the obsolete
+          <sgmltag class="attribte">md5sum</sgmltag>, attributes are optional.
           If these last two attributes are present, they are used to check
           that the source package was downloaded correctly.</para>
   
diff --git a/jhbuild/modtypes/tarball.py b/jhbuild/modtypes/tarball.py
index 41d161c..47eabf5 100644
--- a/jhbuild/modtypes/tarball.py
+++ b/jhbuild/modtypes/tarball.py
@@ -29,7 +29,7 @@ def parse_tarball(node, config, uri, repositories, default_repo):
     version = node.getAttribute('version')
     source_url = None
     source_size = None
-    source_md5 = None
+    source_hash = None
     patches = []
     checkoutdir = None
     autogenargs = ''
@@ -63,7 +63,9 @@ def parse_tarball(node, config, uri, repositories, default_repo):
                             _('module \'%(module)s\' has invalid size attribute (\'%(size)s\')') % {
                                 'module': name, 'size': childnode.getAttribute('size')})
             if childnode.hasAttribute('md5sum'):
-                source_md5 = childnode.getAttribute('md5sum')
+                source_hash = 'md5:' + childnode.getAttribute('md5sum')
+            if childnode.hasAttribute('hash'):
+                source_hash = childnode.getAttribute('hash')
         elif childnode.nodeName == 'patches':
             for patch in childnode.childNodes:
                 if patch.nodeType != patch.ELEMENT_NODE: continue
@@ -88,7 +90,7 @@ def parse_tarball(node, config, uri, repositories, default_repo):
     repo.moduleset_uri = uri
 
     branch = TarballBranch(repo, source_url, version, checkoutdir,
-            source_size, source_md5, None)
+            source_size, source_hash, None)
     branch.patches = patches
 
     return AutogenModule(name, branch,
diff --git a/jhbuild/versioncontrol/tarball.py b/jhbuild/versioncontrol/tarball.py
index b2e28e7..0bb3cce 100644
--- a/jhbuild/versioncontrol/tarball.py
+++ b/jhbuild/versioncontrol/tarball.py
@@ -54,10 +54,12 @@ class TarballRepository(Repository):
         self.href = config.repos.get(name, href)
 
     branch_xml_attrs = ['version', 'module', 'checkoutdir',
-                        'size', 'md5sum', 'source-subdir']
+                        'size', 'md5sum', 'source-subdir',
+                        'hash']
 
     def branch(self, name, version, module=None, checkoutdir=None,
-               size=None, md5sum=None, branch_id=None, source_subdir=None):
+               size=None, md5sum=None, hash=None, branch_id=None,
+               source_subdir=None):
         if name in self.config.branches:
             module = self.config.branches[name]
             if not module:
@@ -68,9 +70,11 @@ class TarballRepository(Repository):
             module = urlparse.urljoin(self.href, module)
         if size is not None:
             size = int(size)
+        if md5sum:
+            hash = 'md5:' + md5sum
         return TarballBranch(self, module=module, version=version,
                              checkoutdir=checkoutdir,
-                             source_size=size, source_md5=md5sum,
+                             source_size=size, source_hash=hash,
                              branch_id=branch_id, source_subdir=source_subdir)
 
     def branch_from_xml(self, name, branchnode, repositories, default_repo):
@@ -100,11 +104,11 @@ class TarballBranch(Branch):
     """A class representing a Tarball."""
 
     def __init__(self, repository, module, version, checkoutdir,
-                 source_size, source_md5, branch_id, source_subdir=None):
+                 source_size, source_hash, branch_id, source_subdir=None):
         Branch.__init__(self, repository, module, checkoutdir)
         self.version = version
         self.source_size = source_size
-        self.source_md5 = source_md5
+        self.source_hash = source_hash
         self.patches = []
         self.quilt = None
         self.branch_id = branch_id
@@ -161,17 +165,18 @@ class TarballBranch(Branch):
                 raise BuildStateError(
                         _('downloaded file size is incorrect (expected %(size1)d, got %(size2)d)')
                                       % {'size1':self.source_size, 'size2':local_size})
-        if self.source_md5 is not None:
-            local_md5 = hashlib.md5()
+        if self.source_hash is not None:
+            algo, hash = self.source_hash.split(':')
+            local_hash = getattr(hashlib, algo)()
             fp = open(localfile, 'rb')
             data = fp.read(32768)
             while data:
-                local_md5.update(data)
+                local_hash.update(data)
                 data = fp.read(32768)
             fp.close()
-            if local_md5.hexdigest() != self.source_md5:
-                raise BuildStateError(_('file MD5 sum is incorrect (expected %(sum1)s, got %(sum2)s)')
-                                      % {'sum1':self.source_md5, 'sum2':local_md5.hexdigest()})
+            if local_hash.hexdigest() != hash:
+                raise BuildStateError(_('file hash is incorrect (expected %(sum1)s, got %(sum2)s)')
+                                      % {'sum1':hash, 'sum2':local_hash.hexdigest()})
 
     def _download_and_unpack(self, buildscript):
         localfile = self._local_tarball
@@ -310,7 +315,7 @@ class TarballBranch(Branch):
                              repo=self.repository.name,
                              version=self.version,
                              size=str(self.source_size),
-                             md5sum=self.source_md5)]
+                             hash=self.source_hash)]
                 + [[sxml.patch(file=patch, strip=str(strip))]
                    for patch, strip in self.patches])
 
diff --git a/modulesets/moduleset.dtd b/modulesets/moduleset.dtd
index c7bf8af..cfee850 100644
--- a/modulesets/moduleset.dtd
+++ b/modulesets/moduleset.dtd
@@ -116,7 +116,8 @@
 <!ATTLIST source
 	href	CDATA	#REQUIRED
 	size	CDATA	#IMPLIED
-	md5sum	CDATA	#IMPLIED>
+	md5sum	CDATA	#IMPLIED
+	hash    CDATA   #IMPLIED>
 
 <!ELEMENT patches (patch*)>
 <!ELEMENT patch EMPTY>
@@ -160,7 +161,8 @@
 	tag             CDATA   #IMPLIED
 	version		CDATA	#IMPLIED
 	size		CDATA	#IMPLIED
-	md5sum		CDATA	#IMPLIED>
+	md5sum		CDATA	#IMPLIED
+	hash		CDATA	#IMPLIED>
 	<!-- override-checkoutdir and update-new-dirs are CVS only
 	     source-subdir is tarballs only -->
 
diff --git a/modulesets/moduleset.rnc b/modulesets/moduleset.rnc
index 7851954..1fc7611 100644
--- a/modulesets/moduleset.rnc
+++ b/modulesets/moduleset.rnc
@@ -71,6 +71,7 @@ branch_tarball = attribute module { xsd:anyURI },
                  attribute version { text },
                  attribute size { text }?,
                  attribute md5sum { text }?,
+                 attribute hash { text }?,
                  element patch {
                    attribute file { text },
                    attribute strip { text }?
@@ -121,7 +122,8 @@ tarball = element tarball {
   (element source {
      attribute href { text },
      attribute size { text }?,
-     attribute md5sum { text }? } &
+     attribute md5sum { text }?,
+     attribute hash { text }? } &
    element patches {
      element patch {
        attribute file { text },



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]