[Reproducible-commits] [debbindiff] 01/01: Add support for cpio archives
Reiner Herrmann
deki-guest at moszumanska.debian.org
Wed Feb 4 20:35:19 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 e11f3d65a2602a368acaadf6661c28bd9bef4ed0
Author: Reiner Herrmann <reiner at reiner-h.de>
Date: Wed Feb 4 21:33:52 2015 +0100
Add support for cpio archives
---
debbindiff/comparators/__init__.py | 2 +
debbindiff/comparators/cpio.py | 75 ++++++++++++++++++++++++++++++++++++++
debian/control | 1 +
3 files changed, 78 insertions(+)
diff --git a/debbindiff/comparators/__init__.py b/debbindiff/comparators/__init__.py
index dd4c6fb..59fc92b 100644
--- a/debbindiff/comparators/__init__.py
+++ b/debbindiff/comparators/__init__.py
@@ -26,6 +26,7 @@ from debbindiff import logger
from debbindiff.comparators.binary import compare_binary_files
from debbindiff.comparators.bzip2 import compare_bzip2_files
from debbindiff.comparators.changes import compare_changes_files
+from debbindiff.comparators.cpio import compare_cpio_files
from debbindiff.comparators.deb import compare_deb_files, compare_md5sums_files
from debbindiff.comparators.elf import \
compare_elf_files, compare_static_lib_files
@@ -69,6 +70,7 @@ COMPARATORS = [
(None, r'\.(p_)?hi$', compare_hi_files),
(None, r'\/\./md5sums$', compare_md5sums_files),
(None, r'\.mo$', compare_mo_files),
+ (None, r'\.cpio$', compare_cpio_files),
(r'^application/x-xz(;|$)', r'\.xz$', compare_xz_files),
(r'^application/x-tar(;|$)', r'\.tar$', compare_tar_files),
(r'^application/zip(;|$)', r'\.(zip|jar)$', compare_zip_files),
diff --git a/debbindiff/comparators/cpio.py b/debbindiff/comparators/cpio.py
new file mode 100644
index 0000000..60efe38
--- /dev/null
+++ b/debbindiff/comparators/cpio.py
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+#
+# debbindiff: highlight differences between two builds of Debian packages
+#
+# Copyright © 2014 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_cpio_content(path, verbose=False):
+ cmd = ['cpio', '--quiet', '-tF', path]
+ if verbose:
+ cmd = ['cpio', '-tvF', path]
+ return subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
+
+
+def extract_cpio_archive(path, destdir):
+ cmd = ['cpio', '--no-absolute-filenames', '--quiet', '-iF',
+ os.path.abspath(path)]
+ logger.debug("extracting %s into %s", path, destdir)
+ p = subprocess.Popen(cmd, shell=False, cwd=destdir)
+ stdout, stderr = p.communicate()
+ p.wait()
+ if p.returncode != 0:
+ logger.error('cpio exited with error code %d', p.returncode)
+
+
+ at binary_fallback
+def compare_cpio_files(path1, path2, source=None):
+ differences = []
+
+ # compare metadata
+ content1 = get_cpio_content(path1, verbose=True)
+ content2 = get_cpio_content(path2, verbose=True)
+ if content1 != content2:
+ differences.append(Difference(
+ content1.splitlines(1), content2.splitlines(1),
+ path1, path2, source="metadata"))
+
+ # compare files contained in archive
+ content1 = get_cpio_content(path1, verbose=False)
+ content2 = get_cpio_content(path2, verbose=False)
+ with make_temp_directory() as temp_dir1:
+ with make_temp_directory() as temp_dir2:
+ extract_cpio_archive(path1, temp_dir1)
+ extract_cpio_archive(path2, temp_dir2)
+ files1 = [ f for f in content1.split('\n') ]
+ files2 = [ f 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 7e21315..5f45445 100644
--- a/debian/control
+++ b/debian/control
@@ -19,6 +19,7 @@ Package: debbindiff
Architecture: all
Depends: binutils-multiarch,
bzip2,
+ cpio,
diffutils,
file,
fontforge-extras,
--
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