[Git][reproducible-builds/diffoscope][master] Refactor .changes and .buildinfo handling to show all details (including the...

Chris Lamb gitlab at salsa.debian.org
Fri May 29 08:19:54 UTC 2020



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
017aacb7 by Chris Lamb at 2020-05-29T09:17:49+01:00
Refactor .changes and .buildinfo handling to show all details (including the GPG header and footer components) even when referenced files are not present. (Closes: reproducible-builds/diffoscope#122)

- - - - -


3 changed files:

- diffoscope/comparators/debian.py
- diffoscope/comparators/utils/container.py
- diffoscope/comparators/utils/file.py


Changes:

=====================================
diffoscope/comparators/debian.py
=====================================
@@ -20,11 +20,9 @@
 
 import re
 import os.path
-import hashlib
 import logging
-import functools
 
-from debian.deb822 import Dsc
+from debian.deb822 import Dsc, Deb822
 
 from diffoscope.changes import Changes
 from diffoscope.difference import Difference
@@ -70,31 +68,6 @@ class DebControlContainer(Container):
         super().__init__(*args, **kwargs)
         self._version_re = DebControlContainer.get_version_trimming_re(self)
 
-    def recognizes(self):
-        if "Checksums-Sha256" not in self.source._deb822:
-            return False
-
-        for x in self.source._deb822.get("Checksums-Sha256"):
-            sha256 = hashlib.sha256()
-
-            # This will not work in nested containers
-            dsc_in_same_dir = os.path.join(
-                os.path.dirname(self.source.path), x["Name"]
-            )
-
-            if not os.path.exists(dsc_in_same_dir):
-                return False
-
-            # Validate whether the checksum matches
-            with open(dsc_in_same_dir, "rb") as f:
-                for buf in iter(functools.partial(f.read, 32768), b""):
-                    sha256.update(buf)
-
-            if sha256.hexdigest() != x["sha256"]:
-                return False
-
-        return True
-
     @staticmethod
     def get_version_trimming_re(dcc):
         version = dcc.source._deb822.get("Version")
@@ -119,13 +92,24 @@ class DebControlContainer(Container):
             "Checksums-Sha256"
         )
 
+        parent_dir = os.path.dirname(self.source.path)
+
         # Show results from debugging packages last; they are rather verbose,
         # masking other more interesting differences due to truncating the
         # output.
-        return sorted(
+        for name in sorted(
             (x["name"] for x in field),
             key=lambda x: (x.endswith(".deb") and "-dbgsym_" in x, x),
-        )
+        ):
+            if not os.path.exists(os.path.join(parent_dir, name)):
+                logger.debug(
+                    "Could not find file %s referenced in %s",
+                    name,
+                    self.source.name,
+                )
+                break
+
+            yield name
 
     def get_member(self, member_name):
         return DebControlMember(self, member_name)
@@ -150,8 +134,26 @@ class DebControlFile(File):
 
         return DummyChanges(Files=[], Version="")
 
+    @staticmethod
+    def _parse_gpg(file):
+        try:
+            with open(file.path) as f:
+                header, _, footer = Deb822.split_gpg_and_payload(f)
+        except EOFError:
+            header = []
+            footer = []
+
+        return [b"\n".join(x).decode("utf-8") for x in (header, footer)]
+
     def compare_details(self, other, source=None):
-        differences = []
+        gpg_a = self._parse_gpg(self)
+        gpg_b = self._parse_gpg(other)
+
+        differences = [
+            Difference.from_text(
+                gpg_a[0], gpg_b[0], self.path, other.path, source="GPG header"
+            )
+        ]
 
         other_deb822 = self._get_deb822(other)
 
@@ -197,6 +199,16 @@ class DebControlFile(File):
                 )
             )
 
+        differences.append(
+            Difference.from_text(
+                gpg_a[1],
+                gpg_b[1],
+                self.path,
+                other.path,
+                source="GPG signature",
+            )
+        )
+
         return differences
 
 


=====================================
diffoscope/comparators/utils/container.py
=====================================
@@ -70,9 +70,6 @@ class Container(metaclass=abc.ABCMeta):
     def get_member(self, member_name):
         raise NotImplementedError()
 
-    def recognizes(self):
-        return True
-
     def get_path_name(self, dest_dir):
         return os.path.join(dest_dir, str(uuid.uuid4()))
 


=====================================
diffoscope/comparators/utils/file.py
=====================================
@@ -252,17 +252,7 @@ class File(metaclass=abc.ABCMeta):
                 "Instantiating a %s for %s", type_name(klass), self.name,
             )
             try:
-                container = klass(self)
-
-                if not container.recognizes():
-                    logger.debug(
-                        "Instantiated a %s for %s, but cannot use it as a container",
-                        type_name(klass),
-                        self.name,
-                    )
-                    continue
-
-                self._as_container = container
+                self._as_container = klass(self)
 
                 logger.debug(
                     "Returning a %s for %s", type_name(klass), self.name,



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/017aacb7d5878c8fdc68482627070e2a80152e1c

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/017aacb7d5878c8fdc68482627070e2a80152e1c
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20200529/b9ca0e1e/attachment.htm>


More information about the rb-commits mailing list