update: handle APKs with a blank versionName

Instead of just crashing, first try to use the versionName as written in the
build metadata, otherwise just let it be blank.  A blank versionName will
cause fdroidclient < 1.3 to crash.  Blank versionNames are not allowed in
the .txt metadata format, only .yml.

closes #477
closes #478
closes fdroidclient#1416
closes fdroidclient#1417
closes fdroidclient#1418
fdroiddata!3061
This commit is contained in:
Hans-Christoph Steiner 2018-04-17 12:15:51 +02:00
parent 9bf9159a77
commit de35f1b05b
5 changed files with 36 additions and 13 deletions

View file

@ -213,6 +213,16 @@ def make_v1(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
if packageName not in apps:
logging.info(_('Ignoring package without metadata: ') + package['apkName'])
continue
if not package.get('versionName'):
app = apps[packageName]
versionCodeStr = str(package['versionCode']) # TODO build.versionCode should be int!
for build in app['builds']:
if build['versionCode'] == versionCodeStr:
versionName = build.get('versionName')
logging.info(_('Overriding blank versionName in {apkfilename} from metadata: {version}')
.format(apkfilename=package['apkName'], version=versionName))
package['versionName'] = versionName
break
if packageName in output_packages:
packagelist = output_packages[packageName]
else:
@ -479,7 +489,17 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
apkel = doc.createElement("package")
apel.appendChild(apkel)
addElement('version', apk['versionName'], doc, apkel)
versionName = apk.get('versionName')
if not versionName:
versionCodeStr = str(apk['versionCode']) # TODO build.versionCode should be int!
for build in app.builds:
if build['versionCode'] == versionCodeStr and 'versionName' in build:
versionName = build['versionName']
break
if versionName:
addElement('version', versionName, doc, apkel)
addElement('versioncode', str(apk['versionCode']), doc, apkel)
addElement('apkname', apk['apkName'], doc, apkel)
addElementIfInApk('srcname', apk, 'srcname', doc, apkel)