[Git][reproducible-builds/diffoscope][master] Attempt compatibility with libarchive-5. (Re: 344)

Chris Lamb (@lamby) gitlab at salsa.debian.org
Thu Jul 13 12:40:16 UTC 2023



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
3c4e378d by Chris Lamb at 2023-07-13T13:39:42+01:00
Attempt compatibility with libarchive-5. (Re: 344)

- - - - -


1 changed file:

- diffoscope/comparators/utils/libarchive.py


Changes:

=====================================
diffoscope/comparators/utils/libarchive.py
=====================================
@@ -122,6 +122,13 @@ libarchive.ArchiveEntry.pathname = property(
 
 
 def list_libarchive(path, ignore_errors=False):
+    def force_str(val):
+        # libarchive ~5 began to return uname and gname as UTF-8 whilst
+        # previous versions returned bytes that required decoding.
+        if not isinstance(val, str):
+            val = val.decode("utf-8", errors="surrogateescape")
+        return val
+
     try:
         with libarchive.file_reader(path) as archive:
             for entry in archive:
@@ -146,18 +153,14 @@ def list_libarchive(path, ignore_errors=False):
                 ) + ".{:06d}".format(entry.mtime_nsec // 1000)
                 if entry.uname:
                     user = "{user:<8} {uid:>7}".format(
-                        user=entry.uname.decode(
-                            "utf-8", errors="surrogateescape"
-                        ),
+                        user=force_str(entry.uname),
                         uid="({})".format(entry.uid),
                     )
                 else:
                     user = entry.uid
                 if entry.gname:
                     group = "{group:<8} {gid:>7}".format(
-                        group=entry.gname.decode(
-                            "utf-8", errors="surrogateescape"
-                        ),
+                        group=force_str(entry.gname),
                         gid="({})".format(entry.gid),
                     )
                 else:



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

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/3c4e378df315a4182da60e50769f1760cc561c2d
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/20230713/8d24ec84/attachment.htm>


More information about the rb-commits mailing list