[diffoscope] 01/01: Fix .deb comparisons when md5sums is wrong or missing

Jérémy Bobbio lunar at moszumanska.debian.org
Wed Dec 16 10:38:15 CET 2015


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch master
in repository diffoscope.

commit 6b2e826240e2e0d39ec6ee1e0d8109676f7f1318
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Wed Dec 16 09:34:17 2015 +0000

    Fix .deb comparisons when md5sums is wrong or missing
    
    Container.get_member() will raise a KeyError instead of returning None if the
    member cannot be found. We change Container.lookup_file() to handle a missing
    member appropriately.
    
    DebFile.md5sums needs to be a dict() and not a set()—all fallback values were
    sadly wrong.
    
    Closes: #808104
---
 diffoscope/comparators/deb.py   | 8 ++++----
 diffoscope/comparators/utils.py | 7 ++++---
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/diffoscope/comparators/deb.py b/diffoscope/comparators/deb.py
index 8448d4b..a6af031 100644
--- a/diffoscope/comparators/deb.py
+++ b/diffoscope/comparators/deb.py
@@ -48,7 +48,7 @@ class DebFile(File):
                 self._md5sums = md5sums_file.parse()
             else:
                 logger.debug('Unable to find a md5sums file')
-                self._md5sums = set()
+                self._md5sums = {}
         return self._md5sums
 
     def compare_details(self, other, source=None):
@@ -77,7 +77,7 @@ class Md5sumsFile(File):
             return md5sums
         except (UnicodeDecodeError, ValueError):
             logger.debug('Malformed md5sums, ignoring.')
-            return set()
+            return {}
 
     def compare(self, other, source=None):
         return Difference(None, self.path, other.path, source='md5sums',
@@ -89,11 +89,11 @@ class DebTarContainer(TarContainer):
         if self.source:
             my_md5sums = self.source.container.source.container.source.md5sums
         else:
-            my_md5sums = set()
+            my_md5sums = {}
         if other.source:
             other_md5sums = other.source.container.source.container.source.md5sums
         else:
-            other_md5sums = set()
+            other_md5sums = {}
         for my_member, other_member, comment in super().comparisons(other):
             if my_member.name == other_member.name and \
                my_md5sums.get(my_member.name, 'my') == other_md5sums.get(other_member.name, 'other'):
diff --git a/diffoscope/comparators/utils.py b/diffoscope/comparators/utils.py
index 6528da2..3fd17a0 100644
--- a/diffoscope/comparators/utils.py
+++ b/diffoscope/comparators/utils.py
@@ -171,10 +171,11 @@ class Container(object, metaclass=ABCMeta):
     def lookup_file(self, *names):
         """Try to fetch a specific file by digging in containers."""
         name, remainings = names[0], names[1:]
-        file = self.get_member(name)
-        logger.debug('lookup_file(%s) -> %s', names, file)
-        if not file:
+        try:
+            file = self.get_member(name)
+        except KeyError:
             return None
+        logger.debug('lookup_file(%s) -> %s', names, file)
         diffoscope.comparators.specialize(file)
         if not remainings:
             return file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list