[diffoscope] 01/01: Add support for AR archives (including Rust .rlib files)
Ximin Luo
infinity0 at debian.org
Mon Jul 18 21:08:03 CEST 2016
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository diffoscope.
commit 53a2143a859682896029bc971e5375ff20a5cd21
Author: Ximin Luo <infinity0 at debian.org>
Date: Mon Jul 18 21:07:03 2016 +0200
Add support for AR archives (including Rust .rlib files)
---
diffoscope/__init__.py | 4 +++-
diffoscope/comparators/__init__.py | 2 ++
diffoscope/comparators/{tar.py => ar.py} | 22 ++++++++++++++++------
diffoscope/comparators/utils.py | 15 ++++++++++-----
4 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/diffoscope/__init__.py b/diffoscope/__init__.py
index 1caebe9..12b37da 100644
--- a/diffoscope/__init__.py
+++ b/diffoscope/__init__.py
@@ -40,7 +40,9 @@ OS_NAMES = { 'arch': 'Arch Linux'
}
class RequiredToolNotFound(Exception):
- PROVIDERS = { 'bzip2': { 'debian': 'bzip2'
+ PROVIDERS = { 'ar': { 'debian': 'ar'
+ , 'arch': 'ar' }
+ , 'bzip2': { 'debian': 'bzip2'
, 'arch': 'bzip2' }
, 'cbfstool': {}
, 'cd-iccdump': { 'debian': 'colord'
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index 9d710f1..b94e84d 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -30,6 +30,7 @@ except ImportError:
from diffoscope import logger, tool_required
from diffoscope.config import Config
from diffoscope.difference import Difference
+from diffoscope.comparators.ar import ArFile
from diffoscope.comparators.binary import \
File, FilesystemFile, NonExistingFile, compare_binary_files
from diffoscope.comparators.bzip2 import Bzip2File
@@ -158,6 +159,7 @@ FILE_CLASSES = (
PpuFile,
RpmFile,
SquashfsFile,
+ ArFile,
TarFile,
XzFile,
ZipFile,
diff --git a/diffoscope/comparators/tar.py b/diffoscope/comparators/ar.py
similarity index 62%
copy from diffoscope/comparators/tar.py
copy to diffoscope/comparators/ar.py
index ab5d8cd..d77e723 100644
--- a/diffoscope/comparators/tar.py
+++ b/diffoscope/comparators/ar.py
@@ -3,6 +3,7 @@
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2014-2015 Jérémy Bobbio <lunar at debian.org>
+# Copyright © 2016 Ximin Luo <infinity0 at pwned.gg>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,23 +18,32 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
+import os.path
import re
from diffoscope.difference import Difference
from diffoscope.comparators.binary import File
from diffoscope.comparators.libarchive import LibarchiveContainer, list_libarchive
from diffoscope.comparators.utils import Command, tool_required
+from diffoscope import logger
-class TarContainer(LibarchiveContainer):
- pass
+class ArContainer(LibarchiveContainer):
+ def get_members(self):
+ members = LibarchiveContainer.get_members(self)
+ cls = members.__class__
+ # for some reason libarchive outputs / and // as member names
+ # filter these out, otherwise they cause exceptions later
+ filtered_out = cls([p for p in members.items() if not os.path.basename(p[0])])
+ logger.debug("ignored ar members %s, probably a libarchive bug", list(filtered_out.keys()))
+ return cls([p for p in members.items() if os.path.basename(p[0])])
-class TarFile(File):
- CONTAINER_CLASS = TarContainer
- RE_FILE_TYPE = re.compile(r'\btar archive\b')
+class ArFile(File):
+ CONTAINER_CLASS = ArContainer
+ RE_FILE_TYPE = re.compile(r'\bar archive\b')
@staticmethod
def recognizes(file):
- return TarFile.RE_FILE_TYPE.search(file.magic_file_type)
+ return ArFile.RE_FILE_TYPE.search(file.magic_file_type)
def compare_details(self, other, source=None):
return [Difference.from_text_readers(list_libarchive(self.path),
diff --git a/diffoscope/comparators/utils.py b/diffoscope/comparators/utils.py
index 41a1eb7..976ecfa 100644
--- a/diffoscope/comparators/utils.py
+++ b/diffoscope/comparators/utils.py
@@ -201,21 +201,26 @@ class Container(object, metaclass=ABCMeta):
while my_members:
my_member_name, my_member = my_members.popitem(last=False)
if my_member_name in other_members:
- yield my_member, other_members.pop(my_member_name), NO_COMMENT
+ yield 1, my_member, other_members.pop(my_member_name), NO_COMMENT
else:
my_reminders[my_member_name] = my_member
my_members = my_reminders
for my_name, other_name, score in diffoscope.comparators.perform_fuzzy_matching(my_members, other_members):
comment = 'Files similar despite different names (difference score: %d)' % score
- yield my_members.pop(my_name), other_members.pop(other_name), comment
+ yield 2, my_members.pop(my_name), other_members.pop(other_name), comment
if Config.general.new_file:
for my_member in my_members.values():
- yield my_member, NonExistingFile('/dev/null', my_member), NO_COMMENT
+ yield 3, my_member, NonExistingFile('/dev/null', my_member), NO_COMMENT
for other_member in other_members.values():
- yield NonExistingFile('/dev/null', other_member), other_member, NO_COMMENT
+ yield 4, NonExistingFile('/dev/null', other_member), other_member, NO_COMMENT
+
+ def tt(self, x):
+ for i in x:
+ logger.info("yielding %s", i)
+ yield tuple(list(i)[1:])
def compare(self, other, source=None):
- return starmap(diffoscope.comparators.compare_commented_files, self.comparisons(other))
+ return starmap(diffoscope.comparators.compare_commented_files, self.tt(self.comparisons(other)))
class NonExistingContainer(Container):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list