[diffoscope] 01/01: Add support for comparing Berkeley DB files. (Closes: #890528)

Chris Lamb chris at chris-lamb.co.uk
Thu Feb 15 17:19:33 CET 2018


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

lamby pushed a commit to branch lamby/890528-add-support-for-berkeley-db-files
in repository diffoscope.

commit ee5a204386451d81e68cee9e359755fff41b7cc5
Author: Chris Lamb <lamby at debian.org>
Date:   Thu Feb 15 16:06:37 2018 +0000

    Add support for comparing Berkeley DB files. (Closes: #890528)
---
 debian/control                        |   1 +
 diffoscope/comparators/__init__.py    |   1 +
 diffoscope/comparators/berkeley_db.py |  44 ++++++++++++++++++++++++++++++
 diffoscope/external_tools.py          |   3 +++
 tests/comparators/test_berkeley_db.py |  49 ++++++++++++++++++++++++++++++++++
 tests/data/berkeley_db_expected_diff  |  28 +++++++++++++++++++
 tests/data/test1.db                   | Bin 0 -> 3072 bytes
 tests/data/test2.db                   | Bin 0 -> 3072 bytes
 8 files changed, 126 insertions(+)

diff --git a/debian/control b/debian/control
index 4e001eb..5d6bac7 100644
--- a/debian/control
+++ b/debian/control
@@ -15,6 +15,7 @@ Build-Depends:
  binutils-multiarch <!nocheck>,
  caca-utils <!nocheck>,
  colord <!nocheck>,
+ db-util <!nocheck>,
  debhelper (>= 11~),
  default-jdk-headless <!nocheck> | default-jdk <!nocheck>,
  dh-python (>= 2.20160818~),
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index 10165f9..a1f7433 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -91,6 +91,7 @@ class ComparatorManager(object):
         ('dtb.DeviceTreeFile',),
         ('ogg.OggFile',),
         ('xsb.XsbFile',),
+        ('berkeley_db.BerkeleyDBFile',),
     )
 
     _singleton = {}
diff --git a/diffoscope/comparators/berkeley_db.py b/diffoscope/comparators/berkeley_db.py
new file mode 100644
index 0000000..b4e817e
--- /dev/null
+++ b/diffoscope/comparators/berkeley_db.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2018 Chris Lamb <lamby at debian.org>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
+
+import re
+
+from diffoscope.tools import tool_required
+from diffoscope.difference import Difference
+
+from .utils.file import File
+from .utils.command import Command
+
+
+class DbDump(Command):
+    @tool_required('db_dump')
+    def cmdline(self):
+        return ('db_dump', '-d', 'a', self.path)
+
+
+class BerkeleyDBFile(File):
+    FILE_TYPE_RE = re.compile(r'^Berkeley DB ')
+
+    def compare_details(self, other, source=None):
+        return [Difference.from_command(
+            DbDump,
+            self.path,
+            other.path,
+            source="Berkeley DB file",
+        )]
diff --git a/diffoscope/external_tools.py b/diffoscope/external_tools.py
index e58a1de..eea15ce 100644
--- a/diffoscope/external_tools.py
+++ b/diffoscope/external_tools.py
@@ -24,6 +24,9 @@ EXTERNAL_TOOLS = {
     'apktool': {
         'debian': 'apktool',
     },
+    'db_dump': {
+        'debian': 'db-util',
+    },
     'bsdtar': {
         'debian': 'libarchive-tools',
         'arch': 'libarchive',
diff --git a/tests/comparators/test_berkeley_db.py b/tests/comparators/test_berkeley_db.py
new file mode 100644
index 0000000..52360b2
--- /dev/null
+++ b/tests/comparators/test_berkeley_db.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2018 Chris Lamb <lamby at debian.org>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
+
+import pytest
+
+from diffoscope.comparators.berkeley_db import BerkeleyDBFile
+
+from ..utils.data import load_fixture, get_data
+from ..utils.tools import skip_unless_tools_exist
+from ..utils.nonexisting import assert_non_existing
+
+db1 = load_fixture('test1.db')
+db2 = load_fixture('test2.db')
+
+
+def test_identification(db1):
+    assert isinstance(db1, BerkeleyDBFile)
+
+
+ at pytest.fixture
+def differences(db1, db2):
+    return db1.compare(db2).details
+
+
+ at skip_unless_tools_exist('db_dump')
+def test_diff(differences):
+    expected_diff = get_data('berkeley_db_expected_diff')
+    assert differences[0].unified_diff == expected_diff
+
+
+ at skip_unless_tools_exist('db_dump')
+def test_compare_non_existing(monkeypatch, db1):
+    assert_non_existing(monkeypatch, db1, has_null_source=False)
diff --git a/tests/data/berkeley_db_expected_diff b/tests/data/berkeley_db_expected_diff
new file mode 100644
index 0000000..c6c6688
--- /dev/null
+++ b/tests/data/berkeley_db_expected_diff
@@ -0,0 +1,28 @@
+@@ -1,25 +1,25 @@
+ In-memory DB structure:
+ hash: 0x110000 (open called, read-only)
+ meta_pgno: 0
+ h_ffactor: 0
+ h_nelem: 31
+-h_hash: 0x7f94124900f0
++h_hash: 0x7f2c389e20f0
+ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ page 0: hash metadata: LSN [0][1]: level 0
+ 	magic: 0x61561
+ 	version: 9
+ 	pagesize: 1024
+ 	type: 8
+ 	metaflags 0
+ 	keys: 0	records: 0
+ 	free list: 0
+ 	last_pgno: 2
+ 	flags: 0
+-	uid: 77 9 1c 3 6 8 0 0 f2 80 ca 56 27 16 0 0 0 0 0 0
++	uid: 77 9 1c 3 6 8 0 0 b8 f9 21 c0 29 16 0 0 0 0 0 0
+ 	max_bucket: 1
+ 	high_mask: 0x1
+ 	low_mask:  0
+ 	ffactor: 25
+ 	nelem: 31
+ 	h_charkey: 0x5e688dd1
+ 	spare points:
diff --git a/tests/data/test1.db b/tests/data/test1.db
new file mode 100644
index 0000000..f0da4a6
Binary files /dev/null and b/tests/data/test1.db differ
diff --git a/tests/data/test2.db b/tests/data/test2.db
new file mode 100644
index 0000000..b1099e3
Binary files /dev/null and b/tests/data/test2.db differ

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


More information about the diffoscope mailing list