1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-06-02 22:00:12 +02:00

category with no apps should be ignored, even if defined in config

https://gitlab.com/fdroid/fdroidclient/-/issues/2619#note_1421280589

The test needed to change because the test index files contained category
definitions that were not ever used in the "copy tests/repo, generate java/gpg
keys, update, and gpgsign" test in tests/run-tests.
This commit is contained in:
Hans-Christoph Steiner 2023-06-07 15:57:58 +02:00
parent 2c566cf68f
commit 48559ecec5
9 changed files with 44 additions and 3 deletions

View File

@ -743,9 +743,16 @@ def make_v2(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
if categories_used_by_apps and not output['repo'].get(CATEGORIES_CONFIG_NAME): if categories_used_by_apps and not output['repo'].get(CATEGORIES_CONFIG_NAME):
output['repo'][CATEGORIES_CONFIG_NAME] = dict() output['repo'][CATEGORIES_CONFIG_NAME] = dict()
# include definitions for "auto-defined" categories, e.g. just used in app metadata
for category in sorted(categories_used_by_apps): for category in sorted(categories_used_by_apps):
if category not in output['repo'][CATEGORIES_CONFIG_NAME]: if category not in output['repo'][CATEGORIES_CONFIG_NAME]:
output['repo'][CATEGORIES_CONFIG_NAME][category] = dict() output['repo'][CATEGORIES_CONFIG_NAME][category] = dict()
# do not include defined categories if no apps use them
for category in list(output['repo'].get(CATEGORIES_CONFIG_NAME, list())):
if category not in categories_used_by_apps:
del output['repo'][CATEGORIES_CONFIG_NAME][category]
msg = _('Category "{category}" defined but not used for any apps!')
logging.warning(msg.format(category=category))
entry = {} entry = {}
entry["timestamp"] = repodict["timestamp"] entry["timestamp"] = repodict["timestamp"]

View File

@ -1863,6 +1863,8 @@ class MetadataTest(unittest.TestCase):
AntiFeatures: AntiFeatures:
- NonFreeNet - NonFreeNet
Categories: Categories:
- Multimedia
- Security
- Time - Time
License: GPL-3.0-only License: GPL-3.0-only
SourceCode: https://github.com/miguelvps/PoliteDroid SourceCode: https://github.com/miguelvps/PoliteDroid

View File

@ -1,6 +1,8 @@
AntiFeatures: AntiFeatures:
- NonFreeNet - NonFreeNet
Categories: Categories:
- Multimedia
- Security
- Time - Time
License: GPL-3.0-only License: GPL-3.0-only
SourceCode: https://github.com/miguelvps/PoliteDroid SourceCode: https://github.com/miguelvps/PoliteDroid

View File

@ -161,6 +161,8 @@ Builds:
versionCode: 6 versionCode: 6
versionName: '1.5' versionName: '1.5'
Categories: Categories:
- Multimedia
- Security
- Time - Time
Changelog: '' Changelog: ''
CurrentVersion: '1.5' CurrentVersion: '1.5'

View File

@ -3,7 +3,7 @@
"version": 20002, "version": 20002,
"index": { "index": {
"name": "/index-v2.json", "name": "/index-v2.json",
"sha256": "b613858aa7a2ec476fcef5c841a5b8ff4b3b0f67f07678da981e2843f49c71ba", "sha256": "5e3c0eaafd99d3518da2bb2bc7565b2ebcb17775a2f4ccc33b7336901ec71a6f",
"size": 53283, "size": 53283,
"numPackages": 10 "numPackages": 10
}, },

View File

@ -174,6 +174,8 @@
"NonFreeNet" "NonFreeNet"
], ],
"categories": [ "categories": [
"Multimedia",
"Security",
"Time" "Time"
], ],
"suggestedVersionName": "1.5", "suggestedVersionName": "1.5",

View File

@ -553,6 +553,8 @@
"metadata": { "metadata": {
"added": 1498176000000, "added": 1498176000000,
"categories": [ "categories": [
"Multimedia",
"Security",
"Time" "Time"
], ],
"issueTracker": "https://github.com/miguelvps/PoliteDroid/issues", "issueTracker": "https://github.com/miguelvps/PoliteDroid/issues",

View File

@ -311,8 +311,8 @@ APK is called F-Droid Privileged Extension.</desc>
<icon>com.politedroid.6.png</icon> <icon>com.politedroid.6.png</icon>
<desc>Activates silent mode during calendar events.</desc> <desc>Activates silent mode during calendar events.</desc>
<license>GPL-3.0-only</license> <license>GPL-3.0-only</license>
<categories>Time</categories> <categories>Multimedia,Security,Time</categories>
<category>Time</category> <category>Multimedia</category>
<web></web> <web></web>
<source>https://github.com/miguelvps/PoliteDroid</source> <source>https://github.com/miguelvps/PoliteDroid</source>
<tracker>https://github.com/miguelvps/PoliteDroid/issues</tracker> <tracker>https://github.com/miguelvps/PoliteDroid/issues</tracker>

View File

@ -1898,6 +1898,30 @@ class UpdateTest(unittest.TestCase):
index['repo'][CATEGORIES_CONFIG_NAME], index['repo'][CATEGORIES_CONFIG_NAME],
) )
def test_empty_categories_not_in_index(self):
"""A category with no apps should be ignored, even if defined in config."""
os.chdir(self.testdir)
os.mkdir('config')
Path('config/categories.yml').write_text('System: {name: S}\nTime: {name: T}\n')
os.mkdir('metadata')
os.mkdir('repo')
Path('config.yml').write_text(
'repo_pubkey: ffffffffffffffffffffffffffffffffffffffff'
)
testapk = os.path.join('repo', 'com.politedroid_6.apk')
shutil.copy(os.path.join(self.basedir, testapk), testapk)
Path('metadata/com.politedroid.yml').write_text('Categories: [Time]')
with mock.patch('sys.argv', ['fdroid update', '--delete-unknown', '--nosign']):
fdroidserver.update.main()
with open('repo/index-v2.json') as fp:
index = json.load(fp)
self.assertEqual(
{'Time': {'name': {'en-US': 'T'}}},
index['repo'][CATEGORIES_CONFIG_NAME],
)
if __name__ == "__main__": if __name__ == "__main__":
os.chdir(os.path.dirname(__file__)) os.chdir(os.path.dirname(__file__))