[Reproducible-commits] [debbindiff] 02/02: Add support for squashfs images

Reiner Herrmann deki-guest at moszumanska.debian.org
Sat Feb 21 21:57:59 UTC 2015


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

deki-guest pushed a commit to branch master
in repository debbindiff.

commit f4c027ee3b54c7a94fa2667eba0daf31966ecb47
Author: Reiner Herrmann <reiner at reiner-h.de>
Date:   Sat Feb 21 22:52:15 2015 +0100

    Add support for squashfs images
    
    Comparing squashfs images could be interesting for
    embedded Linux distributions like OpenWrt.
    
    Added squashfs-tools only to Recommends, as it is
    less relevant for Debian.
---
 README                             | 43 +++++++++++----------
 debbindiff/comparators/__init__.py |  2 +
 debbindiff/comparators/squashfs.py | 79 ++++++++++++++++++++++++++++++++++++++
 debian/control                     |  1 +
 4 files changed, 104 insertions(+), 21 deletions(-)

diff --git a/README b/README
index c74db6a..9013567 100644
--- a/README
+++ b/README
@@ -26,27 +26,28 @@ External dependencies
 The various comparators rely on these external commands being available
 in the path:
 
-| command   | Debian package     |
-+-----------|--------------------|
-| ar        | binutils-multiarch |
-| bzip2     | bzip2              |
-| cpio      | cpio               |
-| file      | file               |
-| ghc       | ghc                |
-| gpg       | gnupg              |
-| gzip      | gzip               |
-| msgunfmt  | gettext            |
-| objdump   | binutils-multiarch |
-| pdftk     | pdftk              |
-| pdftotext | poppler-utils      |
-| readelf   | binutils-multiarch |
-| rpm2cpio  | rpm2cpio           |
-| showttf   | fontforge-extras   |
-| sng       | sng                |
-| vim       | vim                |
-| xxd       | vim-common         |
-| xz        | xz-utils           |
-| zipinfo   | unzip              |
+| command    | Debian package     |
++------------|--------------------|
+| ar         | binutils-multiarch |
+| bzip2      | bzip2              |
+| cpio       | cpio               |
+| file       | file               |
+| ghc        | ghc                |
+| gpg        | gnupg              |
+| gzip       | gzip               |
+| msgunfmt   | gettext            |
+| objdump    | binutils-multiarch |
+| pdftk      | pdftk              |
+| pdftotext  | poppler-utils      |
+| readelf    | binutils-multiarch |
+| rpm2cpio   | rpm2cpio           |
+| showttf    | fontforge-extras   |
+| sng        | sng                |
+| unsquashfs | squashfs-tools     |
+| vim        | vim                |
+| xxd        | vim-common         |
+| xz         | xz-utils           |
+| zipinfo    | unzip              |
 
 Authors
 -------
diff --git a/debbindiff/comparators/__init__.py b/debbindiff/comparators/__init__.py
index 25edb20..cbf9f40 100644
--- a/debbindiff/comparators/__init__.py
+++ b/debbindiff/comparators/__init__.py
@@ -38,6 +38,7 @@ from debbindiff.comparators.haskell import compare_hi_files
 from debbindiff.comparators.pdf import compare_pdf_files
 from debbindiff.comparators.png import compare_png_files
 from debbindiff.comparators.rpm import compare_rpm_files
+from debbindiff.comparators.squashfs import compare_squashfs_files
 from debbindiff.comparators.text import compare_text_files
 from debbindiff.comparators.tar import compare_tar_files
 from debbindiff.comparators.xz import compare_xz_files
@@ -91,6 +92,7 @@ COMPARATORS = [
     (r'^text/plain; charset=(?P<encoding>[a-z0-9-]+)$', None, compare_text_files),
     (r'^application/xml; charset=(?P<encoding>[a-z0-9-]+)$', None, compare_text_files),
     (r'^application/postscript; charset=(?P<encoding>[a-z0-9-]+)$', None, compare_text_files),
+    (None, r'\.squashfs$', compare_squashfs_files),
     (None, r'\.a$', compare_static_lib_files),
     ]
 
diff --git a/debbindiff/comparators/squashfs.py b/debbindiff/comparators/squashfs.py
new file mode 100644
index 0000000..6b92b47
--- /dev/null
+++ b/debbindiff/comparators/squashfs.py
@@ -0,0 +1,79 @@
+# -*- coding: utf-8 -*-
+#
+# debbindiff: highlight differences between two builds of Debian packages
+#
+# Copyright © 2015 Reiner Herrmann <reiner at reiner-h.de>
+#
+# debbindiff 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.
+#
+# debbindiff 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 debbindiff.  If not, see <http://www.gnu.org/licenses/>.
+
+import subprocess
+import os.path
+import debbindiff.comparators
+from debbindiff import logger
+from debbindiff.comparators.utils import binary_fallback, make_temp_directory
+from debbindiff.difference import Difference
+
+
+def get_squashfs_content(path, verbose=True):
+    cmd = ['unsquashfs', '-d', '', '-ls', path]
+    content = ''
+    if verbose:
+        # first get superblock information
+        cmd = ['unsquashfs', '-s', path]
+        content = subprocess.check_output(cmd, shell=False)
+        # and then the verbose file listing
+        cmd = ['unsquashfs', '-d', '', '-lls', path]
+    return content + subprocess.check_output(cmd, shell=False)
+
+
+def extract_squashfs(path, destdir):
+    cmd = ['unsquashfs', '-n', '-f', '-d', destdir, path]
+    logger.debug("extracting %s into %s", path, destdir)
+    p = subprocess.Popen(cmd, shell=False)
+    p.communicate()
+    p.wait()
+    if p.returncode != 0:
+        logger.error('unsquashfs exited with error code %d', p.returncode)
+
+
+ at binary_fallback
+def compare_squashfs_files(path1, path2, source=None):
+    differences = []
+
+    # compare metadata
+    content1 = get_squashfs_content(path1)
+    content2 = get_squashfs_content(path2)
+    if content1 != content2:
+        differences.append(Difference(
+            content1.splitlines(1), content2.splitlines(1),
+            path1, path2, source="metadata"))
+
+    # compare files contained in archive
+    content1 = get_squashfs_content(path1, verbose=False)
+    content2 = get_squashfs_content(path2, verbose=False)
+    with make_temp_directory() as temp_dir1:
+        with make_temp_directory() as temp_dir2:
+            extract_squashfs(path1, temp_dir1)
+            extract_squashfs(path2, temp_dir2)
+            files1 = [ f.lstrip('/') for f in content1.split('\n') ]
+            files2 = [ f.lstrip('/') for f in content2.split('\n') ]
+            for member in sorted(set(files1).intersection(set(files2))):
+                in_path1 = os.path.join(temp_dir1, member)
+                in_path2 = os.path.join(temp_dir2, member)
+                if not os.path.isfile(in_path1) or not os.path.isfile(in_path2):
+                    continue
+                differences.extend(debbindiff.comparators.compare_files(
+                    in_path1, in_path2, source=member))
+
+    return differences
diff --git a/debian/control b/debian/control
index d7b9396..dcd5432 100644
--- a/debian/control
+++ b/debian/control
@@ -38,6 +38,7 @@ Depends: binutils-multiarch,
          xz-utils,
          ${misc:Depends},
          ${python:Depends},
+Recommends: squashfs-tools
 Description: highlight differences between two builds of Debian packages
  debbindiff was designed to easily compare two builds of the same Debian
  package, and understand their differences.

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



More information about the Reproducible-commits mailing list