Commit 80d38082 authored by Chris Lamb's avatar Chris Lamb 💬

Don't fail when run under perversely recursive input files. (Closes: #780761)

Signed-off-by: Chris Lamb's avatarChris Lamb <lamby@debian.org>
parent 9fd7be6f
......@@ -46,6 +46,11 @@ class Container(object, metaclass=abc.ABCMeta):
def __init__(self, source):
self._source = source
# Keep a count of how "nested" we are
self.depth = 0
if hasattr(source, 'container') and source.container is not None:
self.depth = source.container.depth + 1
@property
def source(self):
return self._source
......
......@@ -27,6 +27,7 @@ import subprocess
from diffoscope.exc import RequiredToolNotFound, OutputParsingError, \
ContainerExtractionError
from diffoscope.tools import tool_required
from diffoscope.config import Config
from diffoscope.profiling import profile
from diffoscope.difference import Difference
......@@ -194,6 +195,14 @@ class File(object, metaclass=abc.ABCMeta):
if hasattr(self, 'compare_details'):
details.extend(self.compare_details(other, source))
if self.as_container:
# Don't recursve forever on archive quines, etc.
depth = self._as_container.depth
if depth >= Config().max_container_depth:
msg = "Reached max container depth ({})".format(depth)
logger.debug(msg)
difference.add_comment(msg)
return difference
details.extend(self.as_container.compare(other.as_container))
details = [x for x in details if x]
......
......@@ -35,6 +35,7 @@ class Config(object):
enforce_constraints = True
excludes = ()
compute_visual_diffs = False
max_container_depth = 50
_singleton = {}
......
@@ -1,3 +1,3 @@
-rw-r--r-- 0 1000 1000 4 2015-03-18 15:43:32.000000 debian-binary
-rw-r--r-- 0 1000 1000 149 2015-03-18 19:41:42.000000 control.tar.gz
--rw-r--r-- 0 1000 1000 301 2015-03-18 19:39:56.000000 data.tar.gz
+-rw-r--r-- 0 1000 1000 302 2015-03-18 19:44:07.000000 data.tar.gz
......@@ -63,12 +63,9 @@ def test_identification_deb(quine3, quine4):
@pytest.fixture
def differences_deb(quine3, quine4):
# These tests currently fail
with pytest.raises(RecursionError):
return quine3.compare(quine4).details
return quine3.compare(quine4).details
def test_differences_deb(differences_deb):
assert differences_deb is None
#expected_diff = get_data('quine_deb_expected_diff')
#assert differences_deb[0].unified_diff == expected_diff
expected_diff = get_data('quine_deb_expected_diff')
assert differences_deb[0].unified_diff == expected_diff
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment