From d522bb7e172a3fce502f1bf043336cad4e7f8f52 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 23 Jun 2016 17:58:25 +0200 Subject: [PATCH 1/1] handle APKs with filenames encoded with CP437 The ZIP format has no official encoding :-| so we have to do hacks. The zipfile devs couldn't even sort this out: https://bugs.python.org/issue10614 closes #167 --- fdroidserver/update.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fdroidserver/update.py b/fdroidserver/update.py index e91ef482..abff8b65 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -411,6 +411,14 @@ def getsig(apkpath): return hashlib.md5(hexlify(cert_encoded)).hexdigest() +def get_icon_bytes(apkzip, iconsrc): + '''ZIP has no official encoding, UTF-* and CP437 are defacto''' + try: + return apkzip.read(iconsrc) + except KeyError: + return apkzip.read(iconsrc.encode('utf-8').decode('cp437')) + + def scan_apks(apps, apkcache, repodir, knownapks, use_date_from_apk=False): """Scan the apks in the given repo directory. @@ -613,7 +621,7 @@ def scan_apks(apps, apkcache, repodir, knownapks, use_date_from_apk=False): try: with open(icondest, 'wb') as f: - f.write(apkzip.read(iconsrc)) + f.write(get_icon_bytes(apkzip, iconsrc)) apk['icons'][density] = iconfilename except: @@ -627,7 +635,7 @@ def scan_apks(apps, apkcache, repodir, knownapks, use_date_from_apk=False): iconpath = os.path.join( get_icon_dir(repodir, '0'), iconfilename) with open(iconpath, 'wb') as f: - f.write(apkzip.read(iconsrc)) + f.write(get_icon_bytes(apkzip, iconsrc)) try: im = Image.open(iconpath) dpi = px_to_dpi(im.size[0]) -- 2.30.2