armbian-next: patching: add sanity checks for magic markers matching mbox len & patch_contents not containing magic markers

- case in point, mvebu-edge's disappearing patch in `12-net-dsa-mv88e6xxx.patch`
This commit is contained in:
Ricardo Pardini 2023-01-06 03:29:11 +01:00
parent b7efd70f1a
commit 0b0fa6630b
No known key found for this signature in database
GPG Key ID: 3D38CA12A66C5D02

View File

@ -149,6 +149,15 @@ class PatchFileInDir:
f"File {self.full_file_path()} seems to be a valid mbox file, but it begins with"
f" '{first_line}', but in mbox the 1st line should be a valid From: header"
f" with the magic date.")
# Obtain how many times the magic marker date string is present in the contents
magic_marker_count = contents.count("Mon Sep 17 00:00:00 2001")
if magic_marker_count != len(mbox):
# is_invalid_mbox = True # we might try to recover from this is there's too many
# log.error(
raise Exception(
f"File {self.full_file_path()} seems to be a valid mbox file, but it contains"
f" {magic_marker_count} magic marker dates, while the mbox file has been parsed as"
f" {len(mbox)} patches. Check the file for mbox formatting errors.")
# if there is no emails, it's a diff-only patch file.
if is_invalid_mbox or len(mbox) == 0:
@ -172,6 +181,12 @@ class PatchFileInDir:
f"WARNING: patch file {self.full_file_path()} fragment {counter} contains an empty patch")
continue
# Sanity check: if the patch_contents contains the magic marker, something is _very_ wrong, and we're gonna eat a patch.
if "Mon Sep 17 00:00:00 2001" in patch_contents:
raise Exception(
f"File {self.full_file_path()} fragment {counter} seems to be a valid mbox file, but it contains"
f" the magic date in the patch contents, shouldn't happen. Check the mbox formatting.")
patches.append(PatchInPatchFile(
self, counter, patch_contents, desc, msg['From'], msg['Subject'], msg['Date']))