Commit e47c4bf8 authored by Chris Lamb's avatar Chris Lamb 👀
Browse files

Add a --exclude-directory-metadata=recursive option to support ignoring...

Add a --exclude-directory-metadata=recursive option to support ignoring timestamp (etc.) differences in containers. (Closes: #907600, #36)
parent 12e25406
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ def xattr(path1, path2):


def compare_meta(path1, path2):
    if Config().exclude_directory_metadata:
    if Config().exclude_directory_metadata in ('yes', 'recursive'):
        logger.debug(
            "Excluding directory metadata for paths (%s, %s)", path1, path2)
        return []
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ def compare_root_paths(path1, path2):
    file2 = specialize(FilesystemFile(path2, container=container2))
    difference = compare_files(file1, file2)

    if not Config().exclude_directory_metadata:
    if Config().exclude_directory_metadata in ('no', 'recursive'):
        meta = compare_meta(path1, path2)
        if meta:
            # Create an "empty" difference so we have something to attach file
+8 −5
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import libarchive
import collections

from diffoscope.exc import ContainerExtractionError
from diffoscope.config import Config
from diffoscope.excludes import any_excluded
from diffoscope.tempfiles import get_temporary_directory

@@ -99,6 +100,13 @@ def list_libarchive(path, ignore_errors=False):
    try:
        with libarchive.file_reader(path) as archive:
            for entry in archive:
                name_and_link = entry.name
                if entry.issym:
                    name_and_link = '{entry.name} -> {entry.linkname}'.format(
                        entry=entry)
                if Config().exclude_directory_metadata == 'recursive':
                    yield '{name_and_link}\n'.format(name_and_link=name_and_link)
                    continue
                if entry.isblk or entry.ischr:
                    size_or_dev = '{major:>3},{minor:>3}'.format(
                        major=entry.rdevmajor, minor=entry.rdevminor)
@@ -106,11 +114,6 @@ def list_libarchive(path, ignore_errors=False):
                    size_or_dev = entry.size
                mtime = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(entry.mtime)
                                      ) + '.{:06d}'.format(entry.mtime_nsec // 1000)
                if entry.issym:
                    name_and_link = '{entry.name} -> {entry.linkname}'.format(
                        entry=entry)
                else:
                    name_and_link = entry.name
                if entry.uname:
                    user = '{user:<8} {uid:>7}'.format(user=entry.uname.decode(
                        'utf-8', errors='surrogateescape'), uid='({})'.format(entry.uid))
+8 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import shutil
import os.path
import zipfile

from diffoscope.config import Config
from diffoscope.tools import tool_required
from diffoscope.difference import Difference
from diffoscope.exc import ContainerExtractionError
@@ -163,6 +164,8 @@ class ZipFile(File):

    def compare_details(self, other, source=None):
        differences = []
        zipinfo_difference = None
        if Config().exclude_directory_metadata != 'recursive':
            zipinfo_difference = Difference.from_command(Zipinfo, self.path, other.path) or \
                Difference.from_command(ZipinfoVerbose, self.path, other.path) or \
                Difference.from_command(BsdtarVerbose, self.path, other.path)
@@ -218,6 +221,8 @@ class MozillaZipFile(File):
        return file.file_header[4:8] == b'PK\x01\x02'

    def compare_details(self, other, source=None):
        if Config().exclude_directory_metadata == 'recursive':
            return []
        zipinfo_difference = Difference.from_command(MozillaZipinfo, self.path, other.path) or \
            Difference.from_command(MozillaZipinfoVerbose, self.path, other.path) or \
            Difference.from_command(BsdtarVerbose, self.path, other.path)
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ class Config(object):
        self.enforce_constraints = True
        self.excludes = ()
        self.exclude_commands = ()
        self.exclude_directory_metadata = False
        self.exclude_directory_metadata = 'no'
        self.compute_visual_diffs = False
        self.max_container_depth = 50
        self.use_dbgsym = False
Loading