[diffoscope] 03/09: Fix ELF comparisons against non-existing files

Jérémy Bobbio lunar at moszumanska.debian.org
Tue Jan 19 18:22:30 CET 2016


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

lunar pushed a commit to branch master
in repository diffoscope.

commit e14cbb6b44c723ec7e04e26e335bcdee2853ac26
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Tue Jan 19 14:30:39 2016 +0000

    Fix ELF comparisons against non-existing files
    
    Let's also tighten the tests for non-existing files so they fail when
    comparison falled back on binary diff.
---
 diffoscope/comparators/elf.py   | 16 ++++++++--------
 diffoscope/comparators/utils.py | 16 ++++++++++++++++
 tests/comparators/test_elf.py   |  2 ++
 3 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/diffoscope/comparators/elf.py b/diffoscope/comparators/elf.py
index 37cbf7d..0721ff8 100644
--- a/diffoscope/comparators/elf.py
+++ b/diffoscope/comparators/elf.py
@@ -206,8 +206,7 @@ class ElfSection(File):
 
     @property
     def path(self):
-        raise NotImplementedError('elf sections cannot be extracted')
-        #return self._elf_container.source.path
+        return self._elf_container.source.path
 
     def cleanup(self):
         pass
@@ -225,6 +224,10 @@ class ElfSection(File):
         # Always force diff of the section
         return False
 
+    @property
+    def fuzzy_hash(self):
+        return None
+
     @staticmethod
     def recognizes(file):
         # No file should be recognized as an elf section
@@ -232,22 +235,19 @@ class ElfSection(File):
 
     def compare(self, other, source=None):
         return Difference.from_command(ReadElfSection,
-                self._elf_container.source.path,
-                other._elf_container.source.path,
+                self.path, other.path,
                 command_args=[self._name])
 
 class ElfCodeSection(ElfSection):
     def compare(self, other, source=None):
         return Difference.from_command(ObjdumpDisassembleSection,
-                self._elf_container.source.path,
-                other._elf_container.source.path,
+                self.path, other.path,
                 command_args=[self._name])
 
 class ElfStringSection(ElfSection):
     def compare(self, other, source=None):
         return Difference.from_command(ReadelfStringSection,
-                self._elf_container.source.path,
-                other._elf_container.source.path,
+                self.path, other.path,
                 command_args=[self._name])
 
 
diff --git a/diffoscope/comparators/utils.py b/diffoscope/comparators/utils.py
index 3fd17a0..b6d0cc5 100644
--- a/diffoscope/comparators/utils.py
+++ b/diffoscope/comparators/utils.py
@@ -157,6 +157,14 @@ NO_COMMENT = None
 
 
 class Container(object, metaclass=ABCMeta):
+    def __new__(cls, source):
+        if isinstance(source, NonExistingFile):
+            new = super(Container, NonExistingContainer).__new__(NonExistingContainer)
+            new.__init__(source)
+            return new
+        else:
+            return super(Container, cls).__new__(cls)
+
     def __init__(self, source):
         self._source = source
 
@@ -212,6 +220,14 @@ class Container(object, metaclass=ABCMeta):
         return starmap(diffoscope.comparators.compare_commented_files, self.comparisons(other))
 
 
+class NonExistingContainer(Container):
+    def get_member_names(self):
+        return self.source.other_file.as_container.get_member_names()
+
+    def get_member(self, member_name):
+        return NonExistingFile('/dev/null')
+
+
 class ArchiveMember(File):
     def __init__(self, container, member_name):
         self._container = container
diff --git a/tests/comparators/test_elf.py b/tests/comparators/test_elf.py
index 33d6261..fbf04d1 100644
--- a/tests/comparators/test_elf.py
+++ b/tests/comparators/test_elf.py
@@ -52,6 +52,7 @@ def test_obj_compare_non_existing(monkeypatch, obj1):
     monkeypatch.setattr(Config, 'new_file', True)
     difference = obj1.compare(NonExistingFile('/nonexisting', obj1))
     assert difference.source2 == '/nonexisting'
+    assert len(difference.details) > 0
 
 @pytest.mark.skipif(tool_missing('readelf'), reason='missing readelf')
 def test_diff(obj_differences):
@@ -96,3 +97,4 @@ def test_lib_compare_non_existing(monkeypatch, lib1):
     monkeypatch.setattr(Config, 'new_file', True)
     difference = lib1.compare(NonExistingFile('/nonexisting', lib1))
     assert difference.source2 == '/nonexisting'
+    assert len(difference.details) > 0

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


More information about the diffoscope mailing list