Commit 9415dd7d authored by Ximin Luo's avatar Ximin Luo
Browse files

Add support for AR archives (including Rust .rlib files)

parent 32c32dc1
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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'
+2 −0
Original line number Diff line number Diff line
@@ -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,
+51 −0
Original line number Diff line number Diff line
# -*- coding: utf-8 -*-
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2014-2015 Jérémy Bobbio <lunar@debian.org>
# Copyright © 2016 Ximin Luo <infinity0@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
# 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 <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 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 ArFile(File):
    CONTAINER_CLASS = ArContainer
    RE_FILE_TYPE = re.compile(r'\bar archive\b')

    @staticmethod
    def recognizes(file):
        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),
                                        list_libarchive(other.path),
                                        self.path, other.path, source="file list")]