[diffoscope] 01/01: Also use libarchive to read metadata from ar archives

Jérémy Bobbio lunar at moszumanska.debian.org
Sun Jan 31 11:14:35 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 8df464ebf0db8b04d0baae6a14504f3796e355a0
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Sat Jan 30 13:47:47 2016 +0000

    Also use libarchive to read metadata from ar archives
    
    The output is more precise and less dependent on binutils version.
    
    The command line `ar` tool is not used any more so remove it from the
    required tools.
---
 diffoscope/__init__.py                    |  4 +---
 diffoscope/comparators/deb.py             |  8 ++++----
 diffoscope/comparators/elf.py             | 11 +++++------
 diffoscope/comparators/utils.py           |  8 --------
 tests/comparators/test_deb.py             |  8 --------
 tests/comparators/test_elf.py             |  2 +-
 tests/data/deb_metadata_expected_diff     | 11 ++++++-----
 tests/data/elf_lib_metadata_expected_diff |  8 +++++---
 8 files changed, 22 insertions(+), 38 deletions(-)

diff --git a/diffoscope/__init__.py b/diffoscope/__init__.py
index 0354dcd..133e481 100644
--- a/diffoscope/__init__.py
+++ b/diffoscope/__init__.py
@@ -39,9 +39,7 @@ OS_NAMES = { 'arch': 'Arch Linux'
            }
 
 class RequiredToolNotFound(Exception):
-    PROVIDERS = { 'ar':         { 'debian': 'binutils-multiarch',
-                                  'arch': 'binutils'}
-                , 'bzip2':      { 'debian': 'bzip2',
+    PROVIDERS = { 'bzip2':      { 'debian': 'bzip2',
                                   'arch': 'bzip2'}
                 , 'cbfstool':   {}
                 , 'cmp':        { 'debian': 'diffutils',
diff --git a/diffoscope/comparators/deb.py b/diffoscope/comparators/deb.py
index 1b8491e..6cb659f 100644
--- a/diffoscope/comparators/deb.py
+++ b/diffoscope/comparators/deb.py
@@ -29,7 +29,7 @@ import diffoscope.comparators
 from diffoscope.comparators.binary import File
 from diffoscope.comparators.libarchive import LibarchiveContainer, list_libarchive
 from diffoscope.comparators.utils import \
-    Archive, ArchiveMember, get_ar_content
+    Archive, ArchiveMember
 from diffoscope.comparators.tar import TarContainer
 
 
@@ -86,9 +86,9 @@ class DebFile(File):
         return self._control
 
     def compare_details(self, other, source=None):
-        my_content = get_ar_content(self.path)
-        other_content = get_ar_content(other.path)
-        return [Difference.from_text(my_content, other_content, self.path, other.path, source="metadata")]
+        return [Difference.from_text_readers(list_libarchive(self.path),
+                                             list_libarchive(other.path),
+                                             self.path, other.path, source="file list")]
 
 
 class Md5sumsFile(File):
diff --git a/diffoscope/comparators/elf.py b/diffoscope/comparators/elf.py
index 3e942f4..edc8f2c 100644
--- a/diffoscope/comparators/elf.py
+++ b/diffoscope/comparators/elf.py
@@ -24,8 +24,9 @@ import subprocess
 from diffoscope import tool_required, OutputParsingError
 from diffoscope import logger
 from diffoscope.comparators.binary import File
+from diffoscope.comparators.libarchive import list_libarchive
 from diffoscope.comparators.deb import DebFile, get_build_id_map
-from diffoscope.comparators.utils import get_ar_content, Command, Container
+from diffoscope.comparators.utils import Command, Container
 from diffoscope.difference import Difference
 
 
@@ -419,10 +420,8 @@ class StaticLibFile(File):
 
     def compare_details(self, other, source=None):
         differences = []
-        # look up differences in metadata
-        content1 = get_ar_content(self.path)
-        content2 = get_ar_content(other.path)
-        differences.append(Difference.from_text(
-                               content1, content2, self.path, other.path, source="metadata"))
+        differences.append(Difference.from_text_readers(list_libarchive(self.path),
+                                                        list_libarchive(other.path),
+                                                        self.path, other.path, source="file list"))
         differences.extend(_compare_elf_data(self.path, other.path))
         return differences
diff --git a/diffoscope/comparators/utils.py b/diffoscope/comparators/utils.py
index 94afd23..9df9751 100644
--- a/diffoscope/comparators/utils.py
+++ b/diffoscope/comparators/utils.py
@@ -36,14 +36,6 @@ from diffoscope.difference import Difference
 from diffoscope import logger, tool_required, get_temporary_directory
 
 
- at tool_required('ar')
-def get_ar_content(path):
-    if path == '/dev/null':
-        return ''
-    return subprocess.check_output(
-        ['ar', 'tv', path], stderr=subprocess.STDOUT, shell=False).decode('utf-8')
-
-
 class Command(object, metaclass=ABCMeta):
     def __init__(self, path):
         self._path = path
diff --git a/tests/comparators/test_deb.py b/tests/comparators/test_deb.py
index 3423865..f2c5c5d 100644
--- a/tests/comparators/test_deb.py
+++ b/tests/comparators/test_deb.py
@@ -48,12 +48,10 @@ def test_no_differences(deb1):
 def differences(deb1, deb2):
     return deb1.compare(deb2).details
 
- at pytest.mark.skipif(tool_missing('ar'), reason='missing ar')
 def test_metadata(differences):
     expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/deb_metadata_expected_diff')).read()
     assert differences[0].unified_diff == expected_diff
 
- at pytest.mark.skipif(tool_missing('ar'), reason='missing ar')
 def test_compressed_files(differences):
     assert differences[1].source1 == 'control.tar.gz'
     assert differences[2].source1 == 'data.tar.gz'
@@ -64,7 +62,6 @@ def test_identification_of_md5sums_outside_deb(tmpdir):
     f = specialize(FilesystemFile(path))
     assert type(f) is FilesystemFile
 
- at pytest.mark.skipif(tool_missing('ar'), reason='missing ar')
 def test_identification_of_md5sums_in_deb(deb1, deb2, monkeypatch):
     orig_func = Md5sumsFile.recognizes
     @staticmethod
@@ -78,16 +75,13 @@ def test_identification_of_md5sums_in_deb(deb1, deb2, monkeypatch):
     deb1.compare(deb2)
     assert test_identification_of_md5sums_in_deb.found
 
- at pytest.mark.skipif(tool_missing('ar'), reason='missing ar')
 def test_md5sums(differences):
     assert differences[1].details[0].details[1].comment == 'Files in package differs'
 
- at pytest.mark.skipif(tool_missing('ar'), reason='missing ar')
 def test_identical_files_in_md5sums(deb1, deb2):
     for name in ['./usr/share/doc/test/README.Debian', './usr/share/doc/test/copyright']:
         assert deb1.md5sums[name] == deb2.md5sums[name]
 
- at pytest.mark.skipif(tool_missing('ar'), reason='missing ar')
 def test_identification_of_data_tar(deb1, deb2, monkeypatch):
     orig_func = DebDataTarFile.recognizes
     @staticmethod
@@ -101,7 +95,6 @@ def test_identification_of_data_tar(deb1, deb2, monkeypatch):
     deb1.compare(deb2)
     assert test_identification_of_data_tar.found
 
- at pytest.mark.skipif(tool_missing('ar'), reason='missing ar')
 def test_skip_comparison_of_known_identical_files(deb1, deb2, monkeypatch):
     compared = set()
     orig_func = diffoscope.comparators.compare_files
@@ -112,7 +105,6 @@ def test_skip_comparison_of_known_identical_files(deb1, deb2, monkeypatch):
     deb1.compare(deb2)
     assert './usr/share/doc/test/README.Debian' not in compared
 
- at pytest.mark.skipif(tool_missing('ar'), reason='missing ar')
 def test_compare_non_existing(monkeypatch, deb1):
     monkeypatch.setattr(Config.general, 'new_file', True)
     difference = deb1.compare(NonExistingFile('/nonexisting', deb1))
diff --git a/tests/comparators/test_elf.py b/tests/comparators/test_elf.py
index 95fa947..ece075b 100644
--- a/tests/comparators/test_elf.py
+++ b/tests/comparators/test_elf.py
@@ -92,7 +92,7 @@ def lib_differences(lib1, lib2):
 @pytest.mark.skipif(tool_missing('readelf') or tool_missing('objdump'), reason='missing readelf or objdump')
 def test_lib_differences(lib_differences):
     assert len(lib_differences) == 2
-    assert lib_differences[0].source1 == 'metadata'
+    assert lib_differences[0].source1 == 'file list'
     expected_metadata_diff = open(os.path.join(os.path.dirname(__file__), '../data/elf_lib_metadata_expected_diff')).read()
     assert lib_differences[0].unified_diff == expected_metadata_diff
     assert 'objdump' in lib_differences[1].source1
diff --git a/tests/data/deb_metadata_expected_diff b/tests/data/deb_metadata_expected_diff
index 8c6c572..9b1eb90 100644
--- a/tests/data/deb_metadata_expected_diff
+++ b/tests/data/deb_metadata_expected_diff
@@ -1,6 +1,7 @@
 @@ -1,3 +1,3 @@
- rw-r--r-- 0/0      4 Jun 24 17:40 2015 debian-binary
--rw-r--r-- 0/0    444 Jun 24 17:40 2015 control.tar.gz
--rw-r--r-- 0/0   1626 Jun 24 17:40 2015 data.tar.gz
-+rw-r--r-- 0/0    442 Jun 24 17:40 2015 control.tar.gz
-+rw-r--r-- 0/0   1754 Jun 24 17:40 2015 data.tar.gz
+--rw-r--r--   0        0        0        4 2015-06-24 17:40:03.000000 debian-binary
+--rw-r--r--   0        0        0      444 2015-06-24 17:40:03.000000 control.tar.gz
+--rw-r--r--   0        0        0     1626 2015-06-24 17:40:03.000000 data.tar.gz
++-rw-r--r--   0        0        0        4 2015-06-24 17:40:26.000000 debian-binary
++-rw-r--r--   0        0        0      442 2015-06-24 17:40:26.000000 control.tar.gz
++-rw-r--r--   0        0        0     1754 2015-06-24 17:40:26.000000 data.tar.gz
diff --git a/tests/data/elf_lib_metadata_expected_diff b/tests/data/elf_lib_metadata_expected_diff
index 0df2063..866fb94 100644
--- a/tests/data/elf_lib_metadata_expected_diff
+++ b/tests/data/elf_lib_metadata_expected_diff
@@ -1,3 +1,5 @@
-@@ -1 +1 @@
--rw-r--r-- 1000/1000   1216 Jun 24 12:13 2015 test.o
-+rw-r--r-- 1000/1000   1216 Jun 24 12:14 2015 test.o
+@@ -1,2 +1,2 @@
+-----------   0        0        0       10 2015-06-24 12:14:19.000000 /
+--rw-r--r--   0     1000     1000     1216 2015-06-24 12:13:47.000000 test.o
++----------   0        0        0       10 2015-06-24 12:14:29.000000 /
++-rw-r--r--   0     1000     1000     1216 2015-06-24 12:14:27.000000 test.o

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


More information about the diffoscope mailing list