chiark / gitweb /
update: handle APKs with a blank versionName
authorHans-Christoph Steiner <hans@eds.org>
Tue, 17 Apr 2018 10:15:51 +0000 (12:15 +0200)
committerHans-Christoph Steiner <hans@eds.org>
Tue, 17 Apr 2018 10:36:49 +0000 (12:36 +0200)
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

fdroidserver/index.py
fdroidserver/update.py
tests/repo/duplicate.permisssions_9999999.apk
tests/repo/index-v1.json
tests/repo/index.xml

index 2bb966b724c29c8571a0ab77db2f453863335f26..61552138fcab4e5e54d2b146a53a2006378c699b 100644 (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)
index d7f21e4b458e974e86ad0ae5929d5f04a64ddc7c..2a31e8f121bbfec529d0880bf61fb152f80756f6 100644 (file)
@@ -1208,13 +1208,18 @@ def scan_apk_androguard(apk, apkfile):
 
     apk['packageName'] = apkobject.get_package()
     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()
 
+    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:
         apk['maxSdkVersion'] = apkobject.get_max_sdk_version()
     if apkobject.get_min_sdk_version() is not None:
index ea440c5e057d65126717d7cf23878a02a54e7515..217b873177cf35325ee111b14d07a154c8e347f1 100644 (file)
Binary files a/tests/repo/duplicate.permisssions_9999999.apk and b/tests/repo/duplicate.permisssions_9999999.apk differ
index 90d586ce08a5b20b8d7ba398429a17f11adae167..cda10cf2377ce265718c12b1ed472d7fbc3e4e3a 100644 (file)
       {
         "added": 1513900800000,
         "apkName": "duplicate.permisssions_9999999.apk",
-        "hash": "3d5db5f1ee6fd1d5d9e3c97cc9139b447f538bacd9907f648ba96cfd0848321d",
+        "hash": "8367857fe75f85321ce2c344b34804d0bc193707f6ba03710d025d9030803434",
         "hashType": "sha256",
         "minSdkVersion": "18",
         "packageName": "duplicate.permisssions",
         "sig": "056c9f1554c40ba59a2103009c82b420",
         "signer": "659e1fd284549f70d13fb02c620100e27eeea3420558cce62b0f5d4cf2b77d84",
-        "size": 27507,
+        "size": 27446,
         "targetSdkVersion": "27",
         "uses-permission": [
           [
             null
           ]
         ],
-        "versionCode": 9999999,
-        "versionName": "0.3-7-gb817ac8"
+        "versionCode": 9999999
       }
     ],
     "fake.ota.update": [
index 60136572da6641642a8d86d9c0e77cab2411cfce..ef6988deaa9797a7e300ada566aba60817885f41 100644 (file)
                <marketversion></marketversion>
                <marketvercode>9999999</marketvercode>
                <package>
-                       <version>0.3-7-gb817ac8</version>
                        <versioncode>9999999</versioncode>
                        <apkname>duplicate.permisssions_9999999.apk</apkname>
-                       <hash type="sha256">3d5db5f1ee6fd1d5d9e3c97cc9139b447f538bacd9907f648ba96cfd0848321d</hash>
-                       <size>27507</size>
+                       <hash type="sha256">8367857fe75f85321ce2c344b34804d0bc193707f6ba03710d025d9030803434</hash>
+                       <size>27446</size>
                        <sdkver>18</sdkver>
                        <targetSdkVersion>27</targetSdkVersion>
                        <added>2017-12-22</added>