[Git][reproducible-builds/diffoscope][master] Add note when there are duplicate entries in ZIP files. (Closes:...

Chris Lamb (@lamby) gitlab at salsa.debian.org
Fri Apr 12 08:36:26 UTC 2024



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
607094a5 by FC (Fay) Stegerman at 2024-04-12T09:35:31+01:00
Add note when there are duplicate entries in ZIP files. (Closes: reproducible-builds/diffoscope!140)

- - - - -


1 changed file:

- diffoscope/comparators/zip.py


Changes:

=====================================
diffoscope/comparators/zip.py
=====================================
@@ -184,9 +184,12 @@ class ZipContainer(Archive):
     def open_archive(self):
         zf = zipfile.ZipFile(self.source.path, "r")
         self.name_to_info = {}
+        self.duplicate_entries = 0
         for info in zf.infolist():
             if info.filename not in self.name_to_info:
                 self.name_to_info[info.filename] = info
+            else:
+                self.duplicate_entries += 1
         return zf
 
     def close_archive(self):
@@ -260,6 +263,21 @@ class ZipFile(ZipFileBase):
         r"^((?:iOS App )?Zip archive|Java archive|EPUB document|OpenDocument (Text|Spreadsheet|Presentation|Drawing|Formula|Template|Text Template)|Google Chrome extension)\b"
     )
 
+    def compare(self, other, source=None):
+        x = super().compare(other, source)
+
+        if x is None:
+            return None
+
+        self_dups = getattr(self.as_container, "duplicate_entries", 0)
+        other_dups = getattr(other.as_container, "duplicate_entries", 0)
+        if self_dups:
+            x.add_comment(f"{self.name!r} has {self_dups} duplicate entries")
+        if other_dups:
+            x.add_comment(f"{other.name!r} has {other_dups} duplicate entries")
+
+        return x
+
     def compare_details(self, other, source=None):
         differences = []
         if Config().exclude_directory_metadata != "recursive":



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/607094a55840808b09a95f96cea638ea376cb9d3

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/607094a55840808b09a95f96cea638ea376cb9d3
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/20240412/68161963/attachment.htm>


More information about the rb-commits mailing list