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: if packageName not in apps:
logging.info(_('Ignoring package without metadata: ') + package['apkName']) logging.info(_('Ignoring package without metadata: ') + package['apkName'])
continue 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: if packageName in output_packages:
packagelist = output_packages[packageName] packagelist = output_packages[packageName]
else: else:
@ -479,7 +489,17 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
apkel = doc.createElement("package") apkel = doc.createElement("package")
apel.appendChild(apkel) 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('versioncode', str(apk['versionCode']), doc, apkel)
addElement('apkname', apk['apkName'], doc, apkel) addElement('apkname', apk['apkName'], doc, apkel)
addElementIfInApk('srcname', apk, 'srcname', doc, apkel) addElementIfInApk('srcname', apk, 'srcname', doc, apkel)

View File

@ -1208,13 +1208,18 @@ def scan_apk_androguard(apk, apkfile):
apk['packageName'] = apkobject.get_package() apk['packageName'] = apkobject.get_package()
apk['versionCode'] = int(apkobject.get_androidversion_code()) apk['versionCode'] = int(apkobject.get_androidversion_code())
apk['versionName'] = apkobject.get_androidversion_name()
if apk['versionName'][0] == "@":
version_id = int(apk['versionName'].replace("@", "0x"), 16)
version_id = arsc.get_id(apk['packageName'], version_id)[1]
apk['versionName'] = arsc.get_string(apk['packageName'], version_id)[1]
apk['name'] = apkobject.get_app_name() apk['name'] = apkobject.get_app_name()
versionName = apkobject.get_androidversion_name()
if versionName:
apk['versionName'] = versionName
try: # can be a literal value or a resId
res_id = int(versionName.replace("@", "0x"), 16)
res_id = arsc.get_id(apk['packageName'], res_id)[1]
apk['versionName'] = arsc.get_string(apk['packageName'], res_id)[1]
except ValueError:
pass
if apkobject.get_max_sdk_version() is not None: if apkobject.get_max_sdk_version() is not None:
apk['maxSdkVersion'] = apkobject.get_max_sdk_version() apk['maxSdkVersion'] = apkobject.get_max_sdk_version()
if apkobject.get_min_sdk_version() is not None: if apkobject.get_min_sdk_version() is not None:

View File

@ -288,13 +288,13 @@
{ {
"added": 1513900800000, "added": 1513900800000,
"apkName": "duplicate.permisssions_9999999.apk", "apkName": "duplicate.permisssions_9999999.apk",
"hash": "3d5db5f1ee6fd1d5d9e3c97cc9139b447f538bacd9907f648ba96cfd0848321d", "hash": "8367857fe75f85321ce2c344b34804d0bc193707f6ba03710d025d9030803434",
"hashType": "sha256", "hashType": "sha256",
"minSdkVersion": "18", "minSdkVersion": "18",
"packageName": "duplicate.permisssions", "packageName": "duplicate.permisssions",
"sig": "056c9f1554c40ba59a2103009c82b420", "sig": "056c9f1554c40ba59a2103009c82b420",
"signer": "659e1fd284549f70d13fb02c620100e27eeea3420558cce62b0f5d4cf2b77d84", "signer": "659e1fd284549f70d13fb02c620100e27eeea3420558cce62b0f5d4cf2b77d84",
"size": 27507, "size": 27446,
"targetSdkVersion": "27", "targetSdkVersion": "27",
"uses-permission": [ "uses-permission": [
[ [
@ -336,8 +336,7 @@
null null
] ]
], ],
"versionCode": 9999999, "versionCode": 9999999
"versionName": "0.3-7-gb817ac8"
} }
], ],
"fake.ota.update": [ "fake.ota.update": [

View File

@ -25,11 +25,10 @@
<marketversion></marketversion> <marketversion></marketversion>
<marketvercode>9999999</marketvercode> <marketvercode>9999999</marketvercode>
<package> <package>
<version>0.3-7-gb817ac8</version>
<versioncode>9999999</versioncode> <versioncode>9999999</versioncode>
<apkname>duplicate.permisssions_9999999.apk</apkname> <apkname>duplicate.permisssions_9999999.apk</apkname>
<hash type="sha256">3d5db5f1ee6fd1d5d9e3c97cc9139b447f538bacd9907f648ba96cfd0848321d</hash> <hash type="sha256">8367857fe75f85321ce2c344b34804d0bc193707f6ba03710d025d9030803434</hash>
<size>27507</size> <size>27446</size>
<sdkver>18</sdkver> <sdkver>18</sdkver>
<targetSdkVersion>27</targetSdkVersion> <targetSdkVersion>27</targetSdkVersion>
<added>2017-12-22</added> <added>2017-12-22</added>