[18.05] Fix sniff validation for dynamic compressed types.

This was broken in a bad PR merge/rebase process since the validation mode didn't exist when the initial dynamic compressed types PR was opened.
This commit is contained in:
John Chilton
2018-05-08 15:22:27 -04:00
parent de5ed28120
commit 1083fa4ddb
2 changed files with 18 additions and 3 deletions
+3 -1
View File
@@ -323,7 +323,9 @@ class Registry(object):
if sniff_compressed_types is None:
sniff_compressed_types = getattr(self.config, "sniff_compressed_dynamic_datatypes_default", True)
if not sniff_compressed_types:
attributes["sniff_prefix"] = lambda self, file_prefix: False
# Disable sniff on this type unless in validate_mode().
attributes["sniff_compressed"] = False
compressed_datatype_class = type(auto_compressed_type_name, (datatype_class, binary.CompressedArchive, ), attributes)
if edam_format:
compressed_datatype_class.edam_format = edam_format
+15 -2
View File
@@ -605,13 +605,26 @@ class FilePrefix(object):
def build_sniff_from_prefix(klass):
# Build and attach a sniff function to this class (klass) from the sniff_prefix function
# expected to be defined for the class.
def auto_sniff(self, filename):
file_prefix = FilePrefix(filename)
datatype_compressed = getattr(self, "compressed", False)
if file_prefix.compressed_format and not datatype_compressed:
return False
if datatype_compressed and not file_prefix.compressed_format:
return False
if datatype_compressed:
if not file_prefix.compressed_format:
# This not a compressed file we are looking but the type expects it to be
# must return False.
return False
if not getattr(klass, "sniff_compressed", True) and not self.validate_mode():
# This datatype indicates that it shouldn't be auto-sniffed so return False.
# Do not take this shortcut if validate_mode is True, in that case we aren't
# trying to find a datatype for a file we are trying to verify a datatype
# selection and so should execute the underlying sniff_prefix.
return False
if hasattr(self, "compressed_format"):
if self.compressed_format != file_prefix.compressed_format:
return False