From: Hans-Christoph Steiner Date: Thu, 23 Jun 2016 15:58:25 +0000 (+0200) Subject: handle APKs with filenames encoded with CP437 X-Git-Tag: 0.7.0~40^2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=d522bb7e172a3fce502f1bf043336cad4e7f8f52;hp=1be263e8701087f0ac492a2ef9de33c38d4044ee;p=fdroidserver.git 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 --- 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])