Skip to content
Snippets Groups Projects
Commit b2f9aa3e authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

Use a semantic "AbstractMissingType" type instead of remembering to check for...

Use a semantic "AbstractMissingType" type instead of remembering to check for both "missing" files and missing containers.
parent 4fcd8b53
No related branches found
No related tags found
No related merge requests found
Pipeline #149474 failed with stage
in 12 minutes and 42 seconds
......@@ -29,9 +29,9 @@ from diffoscope.config import Config
from diffoscope.difference import Difference
from .binary import FilesystemFile
from .missing_file import MissingFile
from .missing_file import AbstractMissingType
from .utils.command import Command, our_check_output
from .utils.container import Container, MissingContainer
from .utils.container import Container
logger = logging.getLogger(__name__)
......@@ -147,10 +147,6 @@ def xattr(path1, path2):
)
def is_missing_file(file):
return isinstance(file, MissingFile) or isinstance(file, MissingContainer)
def compare_meta(path1, path2):
if Config().exclude_directory_metadata in ("yes", "recursive"):
logger.debug(
......@@ -252,7 +248,7 @@ class FilesystemDirectory(Directory):
if listing_diff:
differences.append(listing_diff)
if not is_missing_file(other):
if not isinstance(other, AbstractMissingType):
differences.extend(compare_meta(self.name, other.name))
my_container = DirectoryContainer(self)
......
......@@ -29,7 +29,11 @@ from .utils.file import File
logger = logging.getLogger(__name__)
class MissingFile(File):
class AbstractMissingType:
pass
class MissingFile(File, AbstractMissingType):
"""
Represents a missing file when comparing containers.
"""
......
......@@ -24,7 +24,7 @@ import logging
from diffoscope.profiling import profile
from diffoscope.tempfiles import get_temporary_directory
from ..missing_file import MissingFile
from ..missing_file import MissingFile, AbstractMissingType
from .file import File
from .container import Container
......@@ -121,7 +121,7 @@ class ArchiveMember(File):
return False
class MissingArchiveLikeObject:
class MissingArchiveLikeObject(AbstractMissingType):
def getnames(self):
return []
......@@ -132,7 +132,7 @@ class MissingArchiveLikeObject:
pass
class MissingArchive(Archive):
class MissingArchive(Archive, AbstractMissingType):
@property
def source(self):
return None
......
......@@ -29,7 +29,7 @@ from diffoscope.difference import Difference
from diffoscope.excludes import filter_excludes
from diffoscope.progress import Progress
from ..missing_file import MissingFile
from ..missing_file import MissingFile, AbstractMissingType
from .file import path_apparent_size
from .fuzzy import perform_fuzzy_matching
......@@ -188,14 +188,16 @@ class Container(metaclass=abc.ABCMeta):
def compare(self, other, source=None, no_recurse=False):
from .compare import compare_files
from ..directory import compare_meta, is_missing_file
from ..directory import compare_meta
def compare_pair(file1, file2, comment):
difference = compare_files(
file1, file2, source=None, diff_content_only=no_recurse
)
if is_missing_file(file1) or is_missing_file(file2):
if isinstance(file1, AbstractMissingType) or isinstance(
file2, AbstractMissingType
):
# There is no need to compare metadata with a missing file,
# as it doesn't make much sense
meta_differences = []
......@@ -218,7 +220,7 @@ class Container(metaclass=abc.ABCMeta):
)
class MissingContainer(Container):
class MissingContainer(Container, AbstractMissingType):
def get_member_names(self):
return self.source.other_file.as_container.get_member_names()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment