From c47f9ef123de43ca512157fbbf413d7d4f80c92e Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 15 Apr 2020 21:43:41 +0200 Subject: [PATCH] index: xml.dom.minidom no longer sorts attribs It seems now that xml.dom.minidom preserves the order of attributes, rather than sorting them. We assume alpha-sort, so this manually This diff in the test suite running on Debian/testing pointed it out: https://gitlab.com/fdroid/fdroidserver/-/jobs/486970383 ```diff --- /builds/fdroid/fdroidserver/tests/repo/index.xml 2020-04-11 13:36:57.000000000 +0000 +++ repo/index.xml 2020-04-11 13:41:44.000000000 +0000 @@ -1,6 +1,6 @@ - + This is a repository of apps to be used with F-Droid. Applications in this repository are either official binaries built by the original application developers, or are binaries built from source by the admin of f-droid.org using the tools on https://gitlab.com/u/fdroid. http://foobarfoobarfoobar.onion/fdroid/repo https://foo.bar/fdroid/repo @@ -94,9 +94,9 @@ 2017-12-22 056c9f1554c40ba59a2103009c82b420 ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE,CHANGE_WIFI_MULTICAST_STATE,INTERNET,READ_EXTERNAL_STORAGE,WRITE_EXTERNAL_STORAGE - - - + + + @@ -182,9 +182,9 @@ 2013-12-31 eb41d4d6082bb3e81c3d58dbf7fc7332 ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE,BLUETOOTH,BLUETOOTH_ADMIN,CHANGE_NETWORK_STATE,CHANGE_WIFI_MULTICAST_STATE,CHANGE_WIFI_STATE,INTERNET,NFC,RECEIVE_BOOT_COMPLETED - - - + + + ``` --- fdroidserver/index.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/fdroidserver/index.py b/fdroidserver/index.py index 87ab340e..c19b6277 100644 --- a/fdroidserver/index.py +++ b/fdroidserver/index.py @@ -317,13 +317,17 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing parent.appendChild(el) def addElementCheckLocalized(name, app, key, doc, parent, default=''): - '''Fill in field from metadata or localized block + """Fill in field from metadata or localized block For name/summary/description, they can come only from the app source, or from a dir in fdroiddata. They can be entirely missing from the metadata file if there is localized versions. This will fetch those from the localized version if its not available in the metadata file. - ''' + + Attributes should be alpha-sorted, so they must be added in + alpha- sort order. + + """ el = doc.createElement(name) value = app.get(key) @@ -349,21 +353,20 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing doc.appendChild(root) repoel = doc.createElement("repo") - - repoel.setAttribute("name", repodict['name']) + repoel.setAttribute("icon", os.path.basename(repodict['icon'])) if 'maxage' in repodict: repoel.setAttribute("maxage", str(repodict['maxage'])) - repoel.setAttribute("icon", os.path.basename(repodict['icon'])) + repoel.setAttribute("name", repodict['name']) + pubkey, repo_pubkey_fingerprint = extract_pubkey() + repoel.setAttribute("pubkey", pubkey.decode('utf-8')) + repoel.setAttribute("timestamp", '%d' % repodict['timestamp'].timestamp()) repoel.setAttribute("url", repodict['address']) + repoel.setAttribute("version", str(repodict['version'])) + addElement('description', repodict['description'], doc, repoel) for mirror in repodict.get('mirrors', []): addElement('mirror', mirror, doc, repoel) - repoel.setAttribute("version", str(repodict['version'])) - repoel.setAttribute("timestamp", '%d' % repodict['timestamp'].timestamp()) - - pubkey, repo_pubkey_fingerprint = extract_pubkey() - repoel.setAttribute("pubkey", pubkey.decode('utf-8')) root.appendChild(repoel) for command in ('install', 'uninstall'): @@ -542,16 +545,16 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing for permission in sorted_permissions: permel = doc.createElement('uses-permission') - permel.setAttribute('name', permission[0]) if permission[1] is not None: permel.setAttribute('maxSdkVersion', '%d' % permission[1]) apkel.appendChild(permel) + permel.setAttribute('name', permission[0]) for permission_sdk_23 in sorted(apk['uses-permission-sdk-23']): permel = doc.createElement('uses-permission-sdk-23') - permel.setAttribute('name', permission_sdk_23[0]) if permission_sdk_23[1] is not None: permel.setAttribute('maxSdkVersion', '%d' % permission_sdk_23[1]) apkel.appendChild(permel) + permel.setAttribute('name', permission_sdk_23[0]) if 'nativecode' in apk: addElement('nativecode', ','.join(sorted(apk['nativecode'])), doc, apkel) addElementNonEmpty('features', ','.join(sorted(apk['features'])), doc, apkel)