[Git][reproducible-builds/diffoscope][master] 2 commits: Make "error extracting X, falling back to binary comparison E" error message nicer.
Chris Lamb
gitlab at salsa.debian.org
Wed Mar 31 11:23:56 UTC 2021
Chris Lamb pushed to branch master at Reproducible Builds / diffoscope
Commits:
8bdc89ae by Chris Lamb at 2021-03-31T12:23:33+01:00
Make "error extracting X, falling back to binary comparison E" error message nicer.
- - - - -
831cb4e0 by Chris Lamb at 2021-03-31T12:23:33+01:00
If zipinfo(1) shows a difference but we cannot uncover a difference within the underlying .zip or .apk file, add a comment and show the binary comparison. (Closes: reproducible-builds/diffoscope#246)
- - - - -
3 changed files:
- diffoscope/comparators/apk.py
- diffoscope/comparators/utils/file.py
- diffoscope/comparators/zip.py
Changes:
=====================================
diffoscope/comparators/apk.py
=====================================
@@ -31,7 +31,7 @@ from .utils.file import File
from .utils.archive import Archive
from .utils.command import Command
from .utils.compare import compare_files
-from .zip import ZipContainer, zipinfo_differences
+from .zip import ZipContainer, zipinfo_differences, ZipFileBase
from .missing_file import MissingFile
logger = logging.getLogger(__name__)
@@ -208,7 +208,7 @@ class Apksigner(Command):
]
-class ApkFile(File):
+class ApkFile(ZipFileBase):
DESCRIPTION = "Android APK files"
FILE_TYPE_HEADER_PREFIX = b"PK\x03\x04"
FILE_TYPE_RE = re.compile(r"^((Java|Zip) archive data|Dalvik dex file)\b")
=====================================
diffoscope/comparators/utils/file.py
=====================================
@@ -568,9 +568,7 @@ class File(metaclass=abc.ABCMeta):
return None
difference.add_comment(
"Error extracting '{}', falling back to "
- "binary comparison ('{}')".format(
- e.pathname, e.wrapped_exc
- )
+ 'binary comparison: "{}"'.format(e.pathname, e.wrapped_exc)
)
# Append any miscellaneous comments for this file.
=====================================
diffoscope/comparators/zip.py
=====================================
@@ -189,7 +189,34 @@ class ZipContainer(Archive):
return ArchiveMember(self, member_name)
-class ZipFile(File):
+class ZipFileBase(File):
+ def compare(self, other, source=None):
+ x = super().compare(other, source)
+
+ if x is None:
+ return None
+
+ # If we have two or more differences, then we have observed differences
+ # within a nested file. If not, there is likely some difference in
+ # the metadata that zipinfo cannot discover, so we manually fallback to
+ # a binary diff.
+ if len(x.details) >= 2:
+ return x
+
+ x.add_comment(
+ "Archive contents identical but files differ, possibly due "
+ "to different compression levels. Falling back to binary "
+ "comparison."
+ )
+
+ details = self.compare_bytes(other, source=source)
+ if details is not None:
+ x.add_details([details])
+
+ return x
+
+
+class ZipFile(ZipFileBase):
DESCRIPTION = "ZIP archives"
CONTAINER_CLASSES = [ZipContainer]
FILE_TYPE_RE = re.compile(
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/50270b416d381e5847c42d79a579917c6eedc4bf...831cb4e0b638bd0fbd1ee3b8b16983d0f0ad30d0
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/50270b416d381e5847c42d79a579917c6eedc4bf...831cb4e0b638bd0fbd1ee3b8b16983d0f0ad30d0
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20210331/6d267aab/attachment.htm>
More information about the rb-commits
mailing list