[diffoscope] 01/01: iso9660: better check instead of the hacky DOS/MBR thing

Ximin Luo infinity0 at debian.org
Mon Mar 20 18:15:10 CET 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch experimental
in repository diffoscope.

commit 42b66ef1181114654110e27a5bc1c3f8a85a8e9a
Author: Ximin Luo <infinity0 at debian.org>
Date:   Mon Mar 20 18:14:57 2017 +0100

    iso9660: better check instead of the hacky DOS/MBR thing
---
 diffoscope/comparators/iso9660.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/diffoscope/comparators/iso9660.py b/diffoscope/comparators/iso9660.py
index dc32479..80d15ed 100644
--- a/diffoscope/comparators/iso9660.py
+++ b/diffoscope/comparators/iso9660.py
@@ -69,7 +69,19 @@ class ISO9660Listing(Command):
 
 class Iso9660File(File):
     CONTAINER_CLASS = LibarchiveContainer
-    RE_FILE_TYPE = re.compile(r'\b(ISO 9660|DOS/MBR boot sector)\b')
+    RE_FILE_TYPE = re.compile(r'\bISO 9660\b')
+
+    @classmethod
+    def recognizes(cls, file):
+        if file.magic_file_type and cls.RE_FILE_TYPE.search(file.magic_file_type):
+            return True
+        else:
+            # sometimes CDs put things like MBRs at the front, which is an expected
+            # part of the ISO9660 standard, but file(1)/libmagic doesn't detect this
+            # see https://en.wikipedia.org/wiki/ISO_9660#Specifications for detais
+            with open(file.path, "rb") as fp:
+                fp.seek(32769)
+                return fp.read(5) == b'CD001'
 
     def compare_details(self, other, source=None):
         differences = []

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list