Blob Blame History Raw
From f42bcc8ebaaa8922b65de6c72bec327242825cc4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Franti=C5=A1ek=20Zatloukal?= <fzatlouk@redhat.com>
Date: Fri, 29 May 2020 11:26:11 +0200
Subject: [PATCH] [PATCH] Decode rpm_file[rpm.RPMTAG_ARCH] only if it is bytes

https://bugzilla.redhat.com/show_bug.cgi?id=1693774
---
 rpmdeplint/__init__.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/rpmdeplint/__init__.py b/rpmdeplint/__init__.py
index 3280114..4a71d1c 100644
--- a/rpmdeplint/__init__.py
+++ b/rpmdeplint/__init__.py
@@ -37,6 +37,10 @@ arch_map.update({a: 'ppc64p7' for a in ["ppc64p7", "ppc64", "ppc"]})
 arch_map.update({a: 's390x' for a in ["s390x", "s390"]})
 arch_map.update({a: 'sh4a' for a in ["sh4a", "sh4" ]})
 
+def b2s(data):
+    if isinstance(data, bytes):
+        return data.decode('utf-8')
+    return data
 
 def get_hawkey_package_arch(package_name):
     """:param package_name: Package name to determine the arch of."""
@@ -44,7 +48,7 @@ def get_hawkey_package_arch(package_name):
     ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
     with open(package_name, 'rb') as fin:
         rpm_file = ts.hdrFromFdno(fin)
-    pkg_arch = rpm_file[rpm.RPMTAG_ARCH].decode('utf8')
+    pkg_arch = b2s(rpm_file[rpm.RPMTAG_ARCH])
 
     try:
         return arch_map[pkg_arch]
-- 
2.26.2