[diffoscope] 01/01: Add support for AR archives (including Rust .rlib files)
Ximin Luo
infinity0 at debian.org
Mon Jul 18 21:09:02 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 9415dd7d5ea7be1d65e506f06b31ad205b4bcbbb
Author: Ximin Luo <infinity0 at debian.org>
Date: Mon Jul 18 21:08:30 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 ++++++++++++++++------
3 files changed, 21 insertions(+), 7 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),
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list