Commits (3)
......@@ -217,7 +217,10 @@ class DebControlFile(File):
class DotChangesFile(DebControlFile):
DESCRIPTION = "Debian .changes files"
FILE_EXTENSION_SUFFIX = {".changes"}
FILE_TYPE_RE = re.compile(r"^(ASCII text|UTF-8 Unicode text)")
# .changes files can be identified "data" if they contain non-printable
# characters (Re: reproducible-builds/diffoscope#286)
FILE_TYPE_RE = re.compile(r"^(ASCII text|UTF-8 Unicode text|data)")
@classmethod
def recognizes(cls, file):
......@@ -226,13 +229,19 @@ class DotChangesFile(DebControlFile):
try:
file._deb822 = Changes(filename=file.path)
except ChangesFileException:
except ChangesFileException as exc:
logger.warning(
f"Rejecting {file.path} as a Debian .changes file: {exc}"
)
return False
try:
file.validation_msg = None
file._deb822.validate("sha256", check_signature=False)
except FileNotFoundError:
return False
except FileNotFoundError as exc:
# Continue even though this .changes file may be invalid
file.validation_msg = f"{os.path.basename(file.path)} is missing referenced files: {exc}"
logger.warning(file.validation_msg)
return True
......@@ -242,6 +251,10 @@ class DotChangesFile(DebControlFile):
if differences is None:
return None
for x in (self, other):
if x.validation_msg:
differences.add_comment(x.validation_msg)
other_deb822 = self._get_deb822(other)
files = zip(self._deb822.get("Files"), other_deb822.get("Files"))
......
......@@ -113,7 +113,8 @@ def test_dot_changes_invalid(tmpdir):
shutil.copy(TEST_DOT_CHANGES_FILE1_PATH, dot_changes_path)
# we don't copy the referenced .deb
identified = specialize(FilesystemFile(dot_changes_path))
assert not isinstance(identified, DotChangesFile)
# ... but it is identified regardless
assert isinstance(identified, DotChangesFile)
def test_dot_changes_no_differences(dot_changes1):
......